我想在模块中使用“before_action”。
不幸的是,我无法让它发挥作用。
我正在谷歌搜索,但我发现的一切都无法解决问题。
我的模块文件如下所示:
module ShowController
include SimpleController
#before_action :set_object, only: [:show]
def show
set_object
end
end
我想使用注释掉的 before_action 行而不是 show 方法。
因此,我试图包含以下模块:
include AbstractController::Callbacks
include ActiveSupport::Callbacks
include ActiveSupport::Concern
include ActiveSupport
此外,我尝试“需要'active_support/all'”或core_ext。
我收到的 error_message 是:
undefined method `class_attribute' for SimpleController::ShowController:Module
最后什么也没解决,我也没有找到解决办法。
我认为这就是你想要做的:
class SomeController < ActionController::Base
include SimpleController
end
module SimpleController
extend ActiveSupport::Concern
included do
before_action :set_object, only: [:show]
end
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)