Forum: Ruby on Rails Extending a model in a component...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Brett W. (Guest)
on 2006-01-02 23:04
(Received via mailing list)
I know I'm missing something basic, but I need help understanding
something:

I have a model (User) sitting in a component.  I want to extend that
model from my app.  I need to add in a has_many relationship and a
couple of methods.

I was able to mixin the methods using this:

module MyUser
	def my_new_method
		# etc
	end
end

User.send(:include, MyUser::Acts::Chicken)

This just mixes in the new method.  But if I add a 'has_many', I get
an error.

I've tried using the way to extend ActiveRecord (like in a plugin),
but that's not working either.

module MyUser
       def self.append_features(base)
         super
         base.extend(ClassMethods)
       end

       module ClassMethods
         def my_new_method
         end
       end

end

User.send(:include, MyUser)


I'm not understanding the basics of extending a class, not just
mixing things in.  Any pointers on this?

Thanks,
Brett
This topic is locked and can not be replied to.