I tried :include_blank => true
, but it didn't work.
<select>
<%= options_for_select Model.all.collect{|mt| [mt.name, mt.id]} %>
</select>
If I need to add it to the collection, how would you do that?
I tried :include_blank => true
, but it didn't work.
<select>
<%= options_for_select Model.all.collect{|mt| [mt.name, mt.id]} %>
</select>
If I need to add it to the collection, how would you do that?
Since you have tagged as select-tag you can use the option
include_blank
withselect_tag
.From the documentation:
Or you can use
options_for_select
:I think you want this format:
BTW: was assuming Modle was suppose to be Model. To use using collection_select:
If you want a slick solution you can use my gem
rearmed_rails
which has a feature in it that safely monkey patchesoptions_for_select
andoptions_for_collection_select
rails g rearmed_rails:setup
Open
config/initializers/rearmed_rails.rb
and change the following values totrue
Now whenever you need a blank included simply do the following:
I believe the
:include_blank
options only exist forselect
fields tied to a model.Assuming you want to use a plain
<select>
tag instead of a<%= select(...) %>
tied to a model, you can insert a blank entry at the front of your results: