Pergunta

I would like to have a "select an option" option in my dropdown on my rails application.

I am using the collection_select helper tag and it looks something like this:

<%= collection_select(:country, :id, Country.order('name ASC'), :id,:name, {},{:class => "input-xlarge"}) %>

I want the default option of the drop-down to be "Select a country".

Foi útil?

Solução

Use the include_blank option:

<%= collection_select(:country, :id, Country.order('name ASC'),
      :id, :name, 
      { include_blank: 'Select a country' }, 
      { :class => "input-xlarge" }) %>

See the official documentation here

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top