Forum: Ruby on Rails SELECT within SELECT

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F04a22457fcbfee2afc77e77482abe08?d=identicon&s=25 Rails List (railslist)
on 2008-12-21 15:41
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?.
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2008-12-21 16:02
(Received via mailing list)
On Sun, Dec 21, 2008 at 6:41 AM, Rails List
<rails-mailing-list@andreas-s.net> 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 Schroeder ------------------------ hassan.schroeder@gmail.com
This topic is locked and can not be replied to.