I have to objects with common functionalities and a lot of difference. So I want that each have his own table but inherit the common functionalities from a parent class. How can I do this in Rails ? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> I have to objects with common functionalities and a lot of difference. So I want that each have his own table but inherit the common functionalities from a parent class. How can I do this in Rails ?Polymorphic association might be the way to go... See the docs for more... -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
How about just creating your own module and including that in your classes? # lib/common_methods.rb module CommonMethods def all_get_this_method ... end end app/models/company.rb require ''common_methods'' class Company < Active::Record::Base include Commonmethods ... end config/application.rb module Yourapp class Application < Rails::Application config.autoload_paths += %W(#{config.root}/lib) ... -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Matias Fierro wrote in post #959653:> I have to objects with common functionalities and a lot of difference. > So I want that each have his own table but inherit the common > functionalities from a parent class. How can I do this in Rails ?class GenericModel < ActiveRecord::Base self.abstract_class = true # define all the ''common'' methods you want in this class # (including the default behaviors for common methods) # I use methods in this class for providing all my cache # fragment management functionality, rendering model instances # to PDFs, etc, etc end class Person < GenericModel # person-specific methods, and overrides of common methods # from GenericModel end class Address < GenericModel # address-specific methods, and overrides of common methods # from GenericModel end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
It sounds like you may want to use Multiple Table Inheritance in this case. I was looking to set up something similar a while back and came across this article: http://mediumexposure.com/multiple-table-inheritance-active-record/ Hope that helps you out! On Nov 5, 1:32 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> > I have to objects with common functionalities and a lot of difference. So I want that each have his own table but inherit the common functionalities from a parent class. How can I do this in Rails ? > > Polymorphic association might be the way to go... > > See the docs for more...-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Seemingly Similar Threads
- Refactoring module
- pop3 retr responses too large lines - Fails with current python's poplib
- pop3 retr responses too large lines - Fails with current python's poplib
- Próxima reunión del "Grupo de Usuarios de R de Madrid" - Jueves 4-Abril....
- [LLVMdev] Instruction Scheduling - migration from v3.1 to v3.2