Belongs_to question

Hi everyone,

I’m wondering what is the correct way to access a column from a
belongs_to table.

The code below works is OK for the product.category.name line but
fails for the product.make.name line.
Yet they are both the same - I must be doing something basically
wrong ?

Models:
In Product:
belongs_to :category
belongs_to :make

In Category & Make:
has_many :products

TIA - Davo

<% for product in @products %>

<%=h product.name %> <%=h product.category.name %> <%=h product.make.name %> <%= link_to 'Show', :action => 'show', :id => product %> <%= link_to 'Edit', :action => 'edit', :id => product %> <%= link_to 'Destroy', { :action => 'destroy', :id => product }, :confirm => 'Are you sure?', :method => :post %> <% end %>

All Fixed !
The error was caused by Nil data in makes_id for one of the entries -
once I fixed that all came good !
cheers, Dave

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs