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 there any substitute for this for select_tag method?

1

4 Answers

In Rails 3 there is a :prompt option for select_tag:

select_tag "things", many_thing_as_options, :prompt => "Please select"
3

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.

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.