I have this collection and I am trying to display from the list which one I would like to have selected when I am rendering a dropdown. Here is what I got:

<%= options_from_collection_for_select @country, 'id', 'country', :selected => 'USA' %>

Displays the list fine (this is a dropdown of country's by the way). What I would like it to do is pick out USA a the selected option when you drop down the select box, but so far nothin'. Has anyone done this? What do I have to do to select an entry from the options_from_collection_for_select? Thanks,



That doesn't make a WHOLE lot of sense.

options_from_collection_for_select will give you <option> tags. It
takes a collection, and then the value and display value methods to
send to the objects in the collection as it traverses them, creating
the option tags.

Thus, @country, here, would be assumedly a list of country objects
which take the id and country methods as their value and display
values respectively.

There is an optional fourth value, which is the VALUE to match with
the object you want.

For instance:

<%= options_from_collection_for_select @country, 'id', 'country',
@selected_country %>

where @selected_country is the id of the country you want selected.


Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #3 out NOW! http://sensei.zenunit.com/