Forum: Ruby on Rails setting default selection in select options?

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.
Navjeet C. (Guest)
on 2005-12-01 06:52
I am creating a select drop down list using the following syntax:

<%
options = [["Select Country", " "]] +
      @countries.collect {|c|[ c.name, c.id]}
    select( "country", "id", options, {:selected => 0})    %>

where @countries is collection object built from my database. With this
code it always select "United States" country by default but I would
like to select "Select a Country" option. Is it possible to do that? Is
rails hard coded to select "United States" if found in the collection?

Jeet
Navjeet C. (Guest)
on 2005-12-01 16:09
Looks like I have a fix for my problem. I renamed my collection to a
different name and it now shows the first member of the selection
"Select Country" in the drop down. May be the variable name "countries"
is something Rails uses, wierd!!

--Jeet

jeet wrote:
> I am creating a select drop down list using the following syntax:
>
> <%
> options = [["Select Country", " "]] +
>       @countries.collect {|c|[ c.name, c.id]}
>     select( "country", "id", options, {:selected => 0})    %>
>
> where @countries is collection object built from my database. With this
> code it always select "United States" country by default but I would
> like to select "Select a Country" option. Is it possible to do that? Is
> rails hard coded to select "United States" if found in the collection?
>
> Jeet
This topic is locked and can not be replied to.