2015-01-09 14 views
16

モジュールで 'before_action'を使用したいと思います。モジュールで 'before_action'を使用する方法

残念ながら、私はそれを動作させることができませんでした。

私はgoogleingでしたが、見つけたものすべてが問題を解決できませんでした。

私のモジュールファイルには、次のようになります。

module ShowController 
    include SimpleController 
    #before_action :set_object, only: [:show] 

    def show 
    set_object 
    end 
end 

私が代わりにショー方法のoutcommented before_actionラインを使用したいと思います。

したがって、私は、以下のモジュールが含まれるようにしようとしていた。

include AbstractController::Callbacks 
    include ActiveSupport::Callbacks 
    include ActiveSupport::Concern 
    include ActiveSupport 

はまた、私がまたはcore_ext「『active_support /すべてを』必要」しようとしました。

私が受け取るERROR_MESSAGEがある:

undefined method `class_attribute' for SimpleController::ShowController:Module 

は最後に、何も働いていないと私は解決策を見つけることができませんでした。

答えて

25

私は、これはあなたが何をしようとしてあると思う:

class SomeController < ActionController::Base 
    include SimpleController 
end 

module SimpleController 
    extend ActiveSupport::Concern 

    included do 
    before_action :set_object, only: [:show] 
    end 
end 
関連する問題