# Collection\_select has\_many

**URL:** <https://www.ruby-forum.com/t/collection-select-has-many/185244>\
**Category:** Rails\
**Created:** [March 16, 2010, 7:06pm UTC](https://www.ruby-forum.com/t/collection-select-has-many/185244 "2010-03-16T19:06:45Z")\
**Posts on this page:** 4\
**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:** [March 16, 2010, 7:06pm UTC](https://www.ruby-forum.com/t/collection-select-has-many/185244/1 "2010-03-16T19:06:45Z")

</div>

hi

i have two models:  
GeoRegion & GeoRegionSub

which have a has\_many relation to each other.

how can include the has\_many relation in the collection\_select helper? i  
want to have that dropdown where the parent is in black and the children  
indented.

\<%= collection\_select :dl,:parent\_id, GeoRegion.all.???, :id, :title %\>

thx

---

<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:** [March 25, 2010, 6:46pm UTC](https://www.ruby-forum.com/t/collection-select-has-many/185244/2 "2010-03-25T18:46:18Z")

</div>

Same here.  
It’s such a pain to find the appropriate documentation to do that.

---

<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:** [March 25, 2010, 9:25pm UTC](https://www.ruby-forum.com/t/collection-select-has-many/185244/3 "2010-03-25T21:25:30Z")

</div>

u can do that:

\<%= select\_tag :skillset\_id,  
option\_groups\_from\_collection\_for\_select(Skillset.find\_all\_by\_parent\_id(nil),  
:children, :title, :id, :title) %\>

Skillset is a act\_as\_tree model!

hope that helps

---

<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:** [March 26, 2010, 12:12am UTC](https://www.ruby-forum.com/t/collection-select-has-many/185244/4 "2010-03-26T00:12:53Z")

</div>

Thank you.

You just made my day!

I tried your solution then find out this equivalent (better?)  
grouped\_collection\_select

> <https://stackoverflow.com/questions/1447522/is-it-bad-to-hard-code-select-tags-when-using-option-groups-from-collection-for>

Thanks for the help.
