# Get the value of a field pointed by a foreign key

**URL:** <https://www.ruby-forum.com/t/get-the-value-of-a-field-pointed-by-a-foreign-key/92147>\
**Category:** Rails\
**Created:** [April 16, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/get-the-value-of-a-field-pointed-by-a-foreign-key/92147 "2007-04-16T16:48:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pingala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@pingala](https://www.ruby-forum.com/u/pingala)\
**Post date:** [April 16, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/get-the-value-of-a-field-pointed-by-a-foreign-key/92147/1 "2007-04-16T16:48:23Z")

</div>

Hello everybody,

new to Ruby on Rails…  
i’m following the tutorial at

> **[Radar - O’Reilly](https://www.oreilly.com/radar/?page=1)**
>
> Now, next, and beyond: Tracking need-to-know trends at the intersection of business and technology

but i’m having some issues…

now what i want to know is how-to display in a list, the value of a  
field that is pointed by the fk…

example:

table categories:  
id, name

table recipes:  
id, category\_id, title, description, …

where recipes.category\_id is a fk for categories.id

i’ve the list view for the recipes where i want to display something  
like:

Recipe Title Category  
Smoked salmon on rocket leaves Starters

now how can do that?

in my views list.rhtml i’ve something like this:  
\<% for recipe in @recipes %\>

 \<%= link\_to %Q{#{recipe.title}}, :action =\> 'show', :id =\> recipe %\> \<%= link\_to '(del)', { :action =\> 'destroy', :id =\> recipe }, :confirm =\> 'Are you sure?', :post =\> true %\> \<%= link\_to %Q{#{XXXXXXXXXX}}, {:action =\> 'list', :category\_id =\> recipe.category\_id} %\> \<% end %\>

what am i supposed to put in XXXXXXXXXX ? to see the category name  
instead  
of the category\_id? (infact i have recipe.category\_id

thanks for your help.

---

<div class="post-metadata">

**Author:** ![pingala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@pingala](https://www.ruby-forum.com/u/pingala)\
**Post date:** [April 16, 2007, 4:50pm UTC](https://www.ruby-forum.com/t/get-the-value-of-a-field-pointed-by-a-foreign-key/92147/2 "2007-04-16T16:50:57Z")

</div>

I think you need to look into Associations, which manage the table  
relationships in your models.

On 4/16/07, Pingala P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## in my views list.rhtml i’ve something like this: recipe.category\_id} %\>
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
[http://www.web-buddha.co.uk](http://www.web-buddha.co.uk)
