Correct syntax for prompt for select_tag

Hi,

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 %>

Resulting in:
<select id="author_id" name="author_id">
<option value=""></option>
<option value="1">Jim</option>
...

What am I missing?

Ruby 1.9.2p0
Rails 3.0.5

Have you tried with "options"?

options = {:prompt => 'Please Select'}

Have you tried with "options"?
options = {:prompt => 'Please Select'}

Just did, but didn't work :frowning:
The effect is unfortunately the same:

<select id="author_id" name="author_id" prompt="Please Select">
<option value="1">Jim</option>
...

Try this. You can pass a string to include_blank

:include_blank => “Please select”

Tim Shaffer wrote in post #1041162:

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.

The :prompt option was not added until rails 3.1.0

Tim Shaffer wrote in post #1041166:

The :prompt option was not added until rails 3.1.0

Now I understand.
I'll go with what you suggested.
Thanks a lot for your help.