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".

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top