问题描述
我想在模块中使用'before_action'。
不幸的是,我无法完成它。
我是googleing,但是我发现的一切都无法解决问题。
我的模块文件如下所示:
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
另外,我试图require'active_support / all'或者core_ext。
我收到的error_message是: 最后,什么都没有解决,我也找不到解决方案。 我认为这就是你想要做的: I would like to use 'before_action' in a module. Unfortunately, I couldn't get it work. I was googleing, but everything I found couldn't solve the problem. My module file looks like the following: I would like to use the outcommented before_action line instead of the show method. Therefore, I was trying to include the following modules: Additionally, I tried to "require 'active_support/all'" or the core_ext. The error_message I receive is: Finally, nothing worked out and I didn't find a solution. I think this is what you're trying to do: 这篇关于如何在模块中使用'before_action'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
<$ p对于SimpleController :: ShowController:Module
未定义的方法`class_attribute'
class SomeController< ActionController :: Base
包含SimpleController
结束
$ b $模块SimpleController
扩展ActiveSupport ::关注
包含做
before_action: set_object,only:[:show]
end
end
module ShowController
include SimpleController
#before_action :set_object, only: [:show]
def show
set_object
end
end
include AbstractController::Callbacks
include ActiveSupport::Callbacks
include ActiveSupport::Concern
include ActiveSupport
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