I am trying to implement single table inheritance according to the example in Agile Web Development with Rails. I have set up my model like this: class Entry < ActiveRecord::Base belongs_to :customer belongs_to :ticket belongs_to :employee has_many :attachments validates_presence_of :body end class IncomingPost < Entry end class OutgoingPost < Entry end class PrivatePost < Entry end class IncomingCall < Entry end class OutgoingCall < Entry end I can''t instantiate any of the subclasses. If I load the console here is what I get:>> o = OutgoingPost.newNameError: uninitialized constant OutgoingPost from C:/Users/errol.SERENGETI/InstantRails/ruby/lib/ruby/gems/ 1.8/gems/a ctivesupport-1.4.2/lib/active_support/dependencies.rb:266:in `load_missing_const ant'' from C:/Users/errol.SERENGETI/InstantRails/ruby/lib/ruby/gems/ 1.8/gems/a ctivesupport-1.4.2/lib/active_support/dependencies.rb:452:in `const_missing'' from C:/Users/errol.SERENGETI/InstantRails/ruby/lib/ruby/gems/ 1.8/gems/a ctivesupport-1.4.2/lib/active_support/dependencies.rb:464:in `const_missing'' from (irb):1>>It only works if I do something (anything) involving the base Entry class (even if it fails). For example, from the console:>> Entry.find(nil)ActiveRecord::RecordNotFound: Couldn''t find Entry without an ID from C:/Users/errol.SERENGETI/InstantRails/ruby/lib/ruby/gems/ 1.8/gems/a ctiverecord-1.15.3/lib/active_record/base.rb:1012:in `find_from_ids'' from C:/Users/errol.SERENGETI/InstantRails/ruby/lib/ruby/gems/ 1.8/gems/a ctiverecord-1.15.3/lib/active_record/base.rb:419:in `find'' from (irb):1>> o = OutgoingPost.new=> #<OutgoingPost:0x55b363c @attributes={"body"=>nil, "type"=>"OutgoingPost", "e mployee_id"=>nil, "customer_id"=>nil, "ticket_id"=>nil, "created_at"=>nil}, @new _record=true>>>This seems like a pretty messy way to do things. Has anybody else experienced 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 -~----------~----~----~----~------~----~------~--~---
Serengeti wrote:> I am trying to implement single table inheritance according to the > example in Agile Web Development with Rails. > > I have set up my model like this: > > class Entry < ActiveRecord::Base > belongs_to :customer > belongs_to :ticket > belongs_to :employee > has_many :attachments > > validates_presence_of :body > end > > class IncomingPost < Entry > end > > class OutgoingPost < Entry > end > > class PrivatePost < Entry > end > > class IncomingCall < Entry > end > > class OutgoingCall < Entry > end > > I can''t instantiate any of the subclasses. If I load the console here > is what I get: > >>> o = OutgoingPost.new > NameError: uninitialized constant OutgoingPostYou have to put the subclasses in separate files in the models directory: outgoing_call.rb, etc. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks -- that did it. On Jun 25, 11:24 pm, Mark Reginald James <m...-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote:> Serengeti wrote: > > I am trying to implement single table inheritance according to the > > example in Agile Web Development with Rails. > > > I have set up my model like this: > > > class Entry < ActiveRecord::Base > > belongs_to :customer > > belongs_to :ticket > > belongs_to :employee > > has_many :attachments > > > validates_presence_of :body > > end > > > class IncomingPost < Entry > > end > > > class OutgoingPost < Entry > > end > > > class PrivatePost < Entry > > end > > > class IncomingCall < Entry > > end > > > class OutgoingCall < Entry > > end > > > I can''t instantiate any of the subclasses. If I load the console here > > is what I get: > > >>> o = OutgoingPost.new > > NameError: uninitialized constant OutgoingPost > > You have to put the subclasses in separate files in the models > directory: outgoing_call.rb, etc. > > -- > We develop, watch us RoR, in numbers too big to ignore.- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---