# Displaying attribute from related table with a collection\_select

**URL:** <https://www.ruby-forum.com/t/displaying-attribute-from-related-table-with-a-collection-select/209020>\
**Category:** Rails\
**Created:** [July 3, 2011, 8:50am UTC](https://www.ruby-forum.com/t/displaying-attribute-from-related-table-with-a-collection-select/209020 "2011-07-03T08:50:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [July 3, 2011, 8:50am UTC](https://www.ruby-forum.com/t/displaying-attribute-from-related-table-with-a-collection-select/209020/1 "2011-07-03T08:50:00Z")

</div>

I have two tables: Area, AreaType

Area belongs\_to :area\_type  
AreaType has\_many :areas

In my view, I’d like to select from a list of Areas, however, instead  
of using the :area\_type\_id attribute, I would like to use the  
associated area\_type names. Here’s what it looks like now:

\<%= f.collection\_select(:area\_id, Area.where(:subject\_id =\>  
@search.subject\_id), :id, :area\_type\_id, {:include\_blank =\> true} ) %\>

What I want is:  
\<%= f.collection\_select(:area\_id, Area.where(:subject\_id =\>  
@search.subject\_id), :id, area.area\_type.name, {:include\_blank =\>  
true} ) %\>

Anyone know how I would go about creating the area.area\_type.name  
“symbol” to user here?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![SSdemetriusolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a8b319/32.png) [@SSdemetriusolsen](https://www.ruby-forum.com/u/SSdemetriusolsen)\
**Post date:** [July 3, 2011, 9:10am UTC](https://www.ruby-forum.com/t/displaying-attribute-from-related-table-with-a-collection-select/209020/2 "2011-07-03T09:10:59Z")

</div>

Well that was easy! After a little trial and error, I created a new  
method in the area.rb and used the name of that method in the  
collection select 🙂 Cheers
