How to add 'select one...' to options_from_collection_for_select

Viewed 13538

Below is my select-form that works properly.

When the user loads the page it shall show an initial ‘select one...’ with value null or ‘’.

I tried to add it to the Object but wasn’t able to and would be glad to get help!

Thanks a lot!


In my view:

= select_tag 'incident[fault_id]' , options_from_collection_for_select( Fault.all, :id, :label)

I use Rails 3.2 and HAML


Update:

By chance I found something really sweet:

include_blank: 'select one...'

or completely

= f.collection_select :fault_id, Fault.order(:label), :id, :label, include_blank: 'select one...'

In case one likes that too...

Reference: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html

3 Answers
Related