# Belongs\_to question

**URL:** <https://www.ruby-forum.com/t/belongs-to-question/113021>\
**Category:** Rails\
**Created:** [August 26, 2007, 10:46am UTC](https://www.ruby-forum.com/t/belongs-to-question/113021 "2007-08-26T10:46:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Davo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@Davo](https://www.ruby-forum.com/u/Davo)\
**Post date:** [August 26, 2007, 10:46am UTC](https://www.ruby-forum.com/t/belongs-to-question/113021/1 "2007-08-26T10:46:09Z")

</div>

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 %\>

---

<div class="post-metadata">

**Author:** ![Davo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@Davo](https://www.ruby-forum.com/u/Davo)\
**Post date:** [August 26, 2007, 11:23am UTC](https://www.ruby-forum.com/t/belongs-to-question/113021/2 "2007-08-26T11:23:11Z")

</div>

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
