# Displaying foreign key value

**URL:** <https://www.ruby-forum.com/t/displaying-foreign-key-value/145291>\
**Category:** Rails\
**Created:** [August 7, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/displaying-foreign-key-value/145291 "2008-08-07T16:14:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [August 7, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/displaying-foreign-key-value/145291/1 "2008-08-07T16:14:19Z")

</div>

Hi

i have a has\_many app. Imagine Projects \<\> Tasks.  
Creating a new tasks i can select from the dropdown the desired Project.  
that works. Editing the taks , which means changing the project  
association again via dropdown works as well. BUT and thats the  
question:  
how do i display the project name in the tska/show view?  
**Task:**  
\<%=h @task.title %\>  
**Task-Desc:**  
\<%=h @task.desc %\>  
**Project:**  
\<%=h @Project.title %\> ???  
OR  
\<%=h render :text =\> Project.find\_by\_id(@task.project\_id) %\>

HOW is ths working?

thx tom

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [August 7, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/displaying-foreign-key-value/145291/2 "2008-08-07T16:26:42Z")

</div>

> \<%=h @Project.title %\> ???  
> OR  
> \<%=h render :text =\> Project.find\_by\_id(@task.project\_id) %\>
> 
> HOW is ths working?

if in your Task model, you have

belongs\_to :project

then in your view

@task.project.title

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [August 7, 2008, 4:43pm UTC](https://www.ruby-forum.com/t/displaying-foreign-key-value/145291/3 "2008-08-07T16:43:46Z")

</div>

thx, i totally oversaw the missing relations…
