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:

Jim ...

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:

Jim ...

What am I missing?

Ruby 1.9.2p0
Rails 3.0.5

On 16 ene, 15:35, Jim B. [email protected] wrote:

:id, :name, @selected_author), :prompt => “Please select” %>
Resulting in:

Posted viahttp://www.ruby-forum.com/.

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:

Jim ...

Try this:

:include_blank => "Please select

Try this. You can pass a string to include_blank

:include_blank => “Please select”

Tim S. 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 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 S. 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.