0
我现在正在使用Rails 4.2。如何在lib中使用控制器方法与Rails?
我在lib目录下创建了一个模块。我想从app/controllers/applicaiont_controller.rb
调用的维护方法,但它失败:
NoMethodError in ProductsController#index
undefined method `redirect_to` for #<...>
我的lib中的模块,如:
module One
class Display
response = other_method
if response.status == 200
data = 'OK'
else
redirect_to_maintencance 'Maintenance ...'
end
data
end
end
应用程序/控制器/ applicaiont_controller.rb
class ApplicationController < ActionController::Base
# Other methods
def redirect_to_maintencance(message = nil)
redirect_to :maintencance, flash: { maintencance_message: message }
end
end
为什么'#'抛出的错误?如果你只是想要另一个'redirect_to'ish助手,也许你可以在'app/helpers/some_helper.rb'中定义它。 –
Aetherus
因为我想从products_controller的lib目录下使用该模块。 –
然后包含'ProductsController'的代码。您提供的代码与错误无关。 – p4sh4