Forum: Ruby on Rails How can I set selected value on select_tag

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Zhao Y. (Guest)
on 2009-01-09 11:04
This is my select_tag code:

<%=select_tag 'project_version_select',
options_for_select(@project_versions)%>

How can I set the selected value for this select box?
Patrick D. (Guest)
on 2009-01-09 17:19
(Received via mailing list)
On Fri, Jan 9, 2009 at 4:04 AM, Zhao Yi
<removed_email_address@domain.invalid>wrote:

>
> This is my select_tag code:
>
> <%=select_tag 'project_version_select',
> options_for_select(@project_versions)%>
>
> How can I set the selected value for this select box?
>
Look at the documentation for #options_for_select (see
http://www.railsbrain.com/api/rails-2.2.2/doc/inde...).
It takes a second argument which specifies which option should be
selected.

--wpd
Phlip (Guest)
on 2009-01-10 21:35
(Received via mailing list)
Patrick D. wrote:

>     <%=select_tag 'project_version_select',
>     options_for_select(@project_versions)%>
>
>     How can I set the selected value for this select box?
>
> Look at the documentation for #options_for_select (see
> 
http://www.railsbrain.com/api/rails-2.2.2/doc/inde...
> 
<http://www.railsbrain.com/api/rails-2.2.2/doc/inde...).
> It takes a second argument which specifies which option should be selected.

Or instead use

   @my_model_object = look_it_up()
   select 'my_model_object', 'my_attribute',
my_map_of_strings_and_values

the non-_tag versions of all the helpers are much better because they
enforce
cleaner controller actions, and they are aware of your objects and
members so
they can make them sticky.

--
   Phlip
This topic is locked and can not be replied to.