OK. I have 4 models, item/category/subcategory/brand association like following item belongs_to :brands belongs_to :categories belongs_to :subcategories brand has_many :items category has_many :items has_many :subcategories subcategory has_many :items belongs_to :category I also have "category_id", "brand_id", "subcategory_id" as integer, in @items I have following in item/index view <% for item in @items %> <%=h item.category.category_name %> <%=h item.brand.brand_name %> I got undefined method "category" error message, but no error message for "brand" In rails console, I tried like following>> c=Item.find(:first) >> c.brand.brand_nameabove I can got the brand_name correctly. But>> c.category.category_nameI got same error message "undefined method ''category'' " Why would this happen? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 28 Dec 2008, at 17:04, Daniel wrote:> > OK. I have 4 models, item/category/subcategory/brand > > association like following > > item > belongs_to :brands > belongs_to :categories > belongs_to :subcategories >belongs_to should be singular Fred> brand > has_many :items > > category > has_many :items > has_many :subcategories > > subcategory > has_many :items > belongs_to :category > > I also have "category_id", "brand_id", "subcategory_id" as integer, in > @items > > I have following in item/index view > > <% for item in @items %> > <%=h item.category.category_name %> > <%=h item.brand.brand_name %> > > I got undefined method "category" error message, but no error message > for "brand" > > In rails console, I tried like following >>> c=Item.find(:first) >>> c.brand.brand_name > above I can got the brand_name correctly. But >>> c.category.category_name > I got same error message "undefined method ''category'' " > > Why would this happen? > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Fred, Sorry that''s my fault. in my code actually it''s singular. Because "brand" part works fine :-) item belongs_to :brand belongs_to :category belongs_to :subcategory> belongs_to should be singular > > Fred--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---