From: Francesco Date: 2005-11-01T08:57:07+09:00 Subject: Re: [rails] option_groups_from_collection_for_select Francesco wrote: > Hello all. > > I would like to get an option_groups_from_collection like this (from the > docs): > > option_groups_from_collection(@continents, "countries", > "continent_name", "country_id", "country_name", @selected_country.id) > > but with only some "countries", filtered by another field in the > countries table. For example all countries where country_code like '%I%'. > > I dont understand how to do this, because in the controller i have: > > @continents = Continent.find(:all) > > and @continents.countries is called in the view, with no way (that i > know of) to add some conditions. Do i have to work on the @continents > array before passing it to the view? > > > Thanks a lot for your help! All right. Got it. It works like this: option_groups_from_collection_for_select(@categories, "products.find(:all, :conditions => 'somefield = somevalue')", "name", "id", "name")) %> tada! :)