# SELECT within SELECT

**URL:** <https://www.ruby-forum.com/t/select-within-select/156142>\
**Category:** Rails\
**Created:** [December 21, 2008, 3:41pm UTC](https://www.ruby-forum.com/t/select-within-select/156142 "2008-12-21T15:41:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![railslist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@railslist](https://www.ruby-forum.com/u/railslist)\
**Post date:** [December 21, 2008, 3:41pm UTC](https://www.ruby-forum.com/t/select-within-select/156142/1 "2008-12-21T15:41:09Z")

</div>

I am trying to create a drop down of categories and that same drop down  
should also have subcategories of currently selected category.

for category drop down I use something like

\<%= collection\_select(:category, :id, Category.find(:all), :id, :name)  
%\>

but I would like to do something like

\<%= collection\_select(:category, :id, Category.find(:all).each do |cat|  
if cat.name?(currently\_selected) Subcategory.find(:cat.name), :id,  
:name) %\>

any ideas?.

---

<div class="post-metadata">

**Author:** ![railslist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@railslist](https://www.ruby-forum.com/u/railslist)\
**Post date:** [December 21, 2008, 4:02pm UTC](https://www.ruby-forum.com/t/select-within-select/156142/2 "2008-12-21T16:02:28Z")

</div>

On Sun, Dec 21, 2008 at 6:41 AM, Rails L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am trying to create a drop down of categories and that same drop down  
> should also have subcategories of currently selected category.

I think the closest you can come to this with real HTML would be  
using `option_groups_from_collection_for_select`; subcategories  
will be selectable but not categories.

And that’s just the way ‘optgroup’ works, nothing to do with Rails.

## HTH!

Hassan S. ------------------------ removed\_email\_address@domain.invalid
