<select id = "user_w_country" name ="user[w_country]" onchange =
"<%=func%>">
<%= options_from_collection_for_select @country, 'id',
'country', :selected => Countrycode.find_by_country('USA').id %>
</select>
It doesn't complai9n about the code but it doesn't work either. The
documentation for the options_from_collection_for_select says the third
argument is a select option, but I am obviously doing something wrong.
Any ideas? Thanks,
-S
--
Posted via http://www.ruby-forum.com/.
<%= 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,
-S
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.
Julian.
Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #3 out NOW!
http://sensei.zenunit.com/