2015-01-09 7 views
16

मैं मॉड्यूल में 'first_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 
संबंधित मुद्दे