[英]Rails throw NoMethodError in production mode but not in development mode
我有以下代码:
module Api
module V1
class ApplicationController < ::ApplicationController
def succeed_with_object(data, status_code = 200)
render json: {success: true, data_type: 'object', data: data.as_json}, status: status_code
end
end
end
end
其中ApplicationController
是我所有api控制器的父控制器。 :: ApplicationController是Web控制器中的父控制器。 然后我有
module Api
module V1
class AppController < ApplicationController
respond_to :json
skip_before_filter :verify_authenticity_token
def android
file_name = "app-latest-#{ANDROID_VERSION}.apk"
app = MobileApp.new('android', ANDROID_VERSION, "http://example.com/download/#{file_name}")
succeed_with_object(app)
end
end
end
end
然后,当我在生产模式下访问http://example.com/api/v1/app/android时,我遇到了
NoMethodError (undefined method `succeed_with_object' for #<Api::V1::AppController:0x0000000569bbd0>):
app/controllers/api/v1/app_controller.rb:11:in `android'
但是在开发模式下一切正常。 我想知道生产模式和开发模式之间的继承层次结构是否有些不同。
尝试使用以下结构:
class Api::V1::ApiController < ApplicationController
respond_to :json
end
这将是您所有API控制器的父控制器。
然后,您可以使用上面的ApiController扩展您的api控制器。
class Api::V1::TransactionsController < Api::V1::ApiController
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.