ruby on rails - Undefined method in ActiveSupport concern -


i have model extends activerecord::base , includes concern:

class user < activerecord::base     include userconcern      def self.create_user()         ...         results = some_method()     end  end 

userconcern stored in concerns directory:

module userconcern     extend activesupport::concern      def some_method()         ...     end end 

i getting run-time error when try create new user calling create_user method looks this:

undefined method 'some_method' #<class:0x000000...> 

i have 2 questions this:

  1. why some_method undefined? seems me including statement include userconcern. have user class extending activerecord::base? or maybe fact calling some_methods() class method (i.e. self.create_user())?

  2. why run-time error refer #<class:0x000000...> instead of #<user:0x000000...>?

try it

models/concerns/user_concern.rb:

module userconcern   extend activesupport::concern    def some_instance_method     'some_instance_method'   end    included     def self.some_class_method       'some_class_method'     end   end end 

models/user.rb:

class user < activerecord::base   include userconcern   def self.create_user     self.some_class_method   end end 

rails console:

user = user.new user.some_instance_method # => "some_instance_method"  user.some_class_method # => "some_class_method"  user.create_user # => "some_class_method" 

http://api.rubyonrails.org/classes/activesupport/concern.html


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -