Can I Include Blank Field in Select_Tag?
Is It Possible to Add an Option Like: Include_Blank => 'Please Select' in a Method Select_Tag Like It Is Possible with the Select Method? It Seems Not to Work...
Is it possible to add an option like :include_blank => 'Please Select' in a method select_tag like it is possible with the select method? It seems not to work. Is there any substitute for this for select_tag method?
4 Answers
In Rails 3 there is a :prompt option for select_tag:
select_tag "things", many_thing_as_options, :prompt => "Please select"
Must Read
Edit: This answer is only applicable to Rails 2.
Rails 3 has improved the experience, so you do not have to use this hack. Ahmad hamza's answer directly provides the Rails 3 way of answering the question, as well as providing the more user friendly behaviour of providing a prompt.
The rest of the response remains as is for any one stuck maintaining a Rails 2 project.