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_name
above I can got the brand_name correctly. Butc.category.category_name
I got same error message "undefined method ‘category’ "
Why would this happen?