Default value in select_tag

Dear all

I have the following select_tag in view

<%= select_tag(:event_status, options_for_select([""]) +
options_from_collection_for_select(@event_status_list, :value, :detail))
%>

which give the following drop down item
“”
Ignore
Problem
Normal
Handling

I want to set the default value to “Problem”. I have used google but
cannot find my desired output.

I try the following, but failed…

<%= select_tag(:event_status, options_for_select([""]) +
options_from_collection_for_select(@event_status_list||“Problem”,
:value, :detail)) %>

Can anyone give me some hints.

Thank you.
Valentino

Valentino L. wrote:

<%= select_tag(:event_status, options_for_select([""]) +
options_from_collection_for_select(@event_status_list, :value, :detail))
%>

The trick is recognizing options_from_collection_for_select(), not
select_tag(),
creates the , and only they can use the selected=‘selected’
attribute.

Google for options_from_collection_for_select() and “default value”…

<%= select_tag(:event_status, options_for_select([“”]) +
options_from_collection_for_select
(@event_status_list||“Problem”, :value, :detail, @selected_status))
%>

See

Hadn’t realized that you were trying to specify “Problem” as the
default. Note that if your :value method gives another result for
“Problem”, like for example, 1, then you have to change the selected
field accordingly.

<%= select_tag(:event_status, options_for_select([""]) +
options_from_collection_for_select
(@event_status_list, :value, :detail, “Problem”))
%>