【发布时间】:2015-03-08 03:52:20
【问题描述】:
我想在模块中使用“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
最后,什么都没解决,我也没有找到解决办法。
【问题讨论】:
-
如果您收到
undefined method 'class_attribute',您可能需要将 ShowController 设为类而不是模块。
标签: ruby-on-rails module gem