I have a polymorphic thingy called fields and I need to on each and every model, so I''d like to do the has_many from the base class, like this... ActiveRecord::Base.class_eval do has_many :fields, :as => :model, :dependent => true end It fails with this no method error (class_of_active_record_descendant) /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/ base.rb:1369:in `class_of_active_record_descendant'':NoMethodError: undefined method `abstract_class?'' for Object:Class Is there a better way to do this??? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Instead of doing a class_eval, have you tried this: ActiveRecord::Base has_many :fields, :as => :model, :dependent => true end If you put this in a some_name.rb file in your models, the AR::Base class will be extended with the functionality, which will then be inherited by your models. It might work... Brent -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Seemingly Similar Threads
- add comments to ALL models (ie automatically add has_many)
- undefined method `has_many' for Object:Class +Savage Beast 2.3 plugin
- Execute code when an inheritance happens, or disabling STI
- class_eval in ROR''s attribure_accessor.rb
- ActiveRecord::AssociationTypeMismatch (User(#54754560) expected, got User(#54510280))