Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[rails] option_groups_from_collection_for_select

19 views
Skip to first unread message

Francesco

unread,
Oct 31, 2005, 1:42:20 PM10/31/05
to
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!

Francesco

unread,
Oct 31, 2005, 6:54:14 PM10/31/05
to

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! :)

0 new messages