i am trying to use single table inheritance for the first time and not having much luck so far. in my model i have: class NavigationItem < ActiveRecord::Base end class MenuItem < NavigationItem end class LinkItem < NavigationItem end but when i use the console to create a new record like menu = MenuItem.new i get an error saying: NameError: uninitialized constant MenuItem am i doing something wrong? -- 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 -~----------~----~----~----~------~----~------~--~---
Hey Josh, Have a look at the following wiki; http://wiki.rubyonrails.org/rails/pages/SingleTableInheritance, specifically the ''note'' part.* "Note:* Rails must ‘see’ the file containing the STI classes before it can use them, otherwise you’ll end up with a “uninitialized constant” error. This can be a problem if the name of the class and the name of the file defining it are not the same, e.g. you have the model ‘Manager’ in the file ‘employees.rb’. Rails will not be able to divine the filename from the class name in this case." I take it that this is what is biting you :) Regards Stef Josh Kieschnick wrote:> i am trying to use single table inheritance for the first time and not > having much luck so far. > > in my model i have: > > class NavigationItem < ActiveRecord::Base > end > > class MenuItem < NavigationItem > end > > class LinkItem < NavigationItem > end > > but when i use the console to create a new record like menu = > MenuItem.new i get an error saying: NameError: uninitialized constant > MenuItem > > am i doing something wrong? > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
yes, that is what i was doing. so what is the better practice? on the wiki it suggests adding “model :employees” to the application.rb, but it sounds like i could do that or just put the classes in separate files that have matching names? Stef Telford wrote:> Hey Josh, > Have a look at the following wiki; > http://wiki.rubyonrails.org/rails/pages/SingleTableInheritance, > specifically the ''note'' part.* "Note:* Rails must ‘see’ the file > containing the STI classes before it can use them, otherwise you’ll end > up with a “uninitialized constant” error. This can be a problem if the > name of the class and the name of the file defining it are not the same, > e.g. you have the model ‘Manager’ in the file ‘employees.rb’. Rails will > not be able to divine the filename from the class name in this case." > > I take it that this is what is biting you :) > Regards > Stef-- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hey Josh, Well, personally, I am all for thinking about the person that comes -after- you (so to speak). Putting them into seperate model files is probably ''saner'' in my view. Even if your only doing this on your own application, its probably a good habit to get into .. but .. thats jst my 2cents and all coding style is highly subjective. I would hate to come across as a pythonista ;P :P Regards Stef Josh Kieschnick wrote:> yes, that is what i was doing. so what is the better practice? on the > wiki it suggests adding “model :employees” to the application.rb, but it > sounds like i could do that or just put the classes in separate files > that have matching names? > > Stef Telford wrote: > >> Hey Josh, >> Have a look at the following wiki; >> http://wiki.rubyonrails.org/rails/pages/SingleTableInheritance, >> specifically the ''note'' part.* "Note:* Rails must ‘see’ the file >> containing the STI classes before it can use them, otherwise you’ll end >> up with a “uninitialized constant” error. This can be a problem if the >> name of the class and the name of the file defining it are not the same, >> e.g. you have the model ‘Manager’ in the file ‘employees.rb’. Rails will >> not be able to divine the filename from the class name in this case." >> >> I take it that this is what is biting you :) >> Regards >> Stef >> > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---