What is the correct syntax for adding a prompt to a select_tag?
I have this, which works as expected:
<%= select_tag "author_id", options_from_collection_for_select(@authors,
:id, :name, @selected_author) %>
When I try and add a prompt, like this:
<%= select_tag "author_id", options_from_collection_for_select(@authors,
:id, :name, @selected_author), :prompt => "Please select" %>
I just get:
<select id="author_id" name="author_id" prompt="Please select">
<option value="1">Jim</option>
...
However, adding a blank field works fine:
<%= select_tag "author_id", options_from_collection_for_select(@authors,
:id, :name, @selected_author), :include_blank => true %>
Try this. You can pass a string to include_blank
:include_blank => "Please select"
Thanks a lot, that works fine!
Out of interest though, this passes "author_id" in the params as an
empty string, so I have to write:
if params.has_key?(:author_id) and not params[:author_id].empty?
instead of just:
if params.has_key?(:author_id)
Does prompt pass any value in in the params?
It would also be nice to understand why :prompt => true isn't working.