Hello Everyone
I have a select_tag which I populate using a map, I use
options_for_select method to pass the map and "selected" value. For
some
reason I can not get the option "selected" based on the value I pass
to
the selected attribute. Here is the code
<%= select_tag :current_course,
options_for_select( Course.find(:all).map {|p| [p.title,p.id]},
@selected )
%>
The corresponding HTML produced is
<select id="current_course" name="current_course" >
<option value="1">Mathematics I</option>
<option value="2">Engineering Design</option>
<option value="3">Technical Writing</option>
</select>
When I printed the value of @selected variable, it is either 1,2 or 3.
But I never get any option selected.
Interestingly if instead of passing @selected, I pass 1, 2 or 3 as in
the code below
<%= select_tag :current_course,
options_for_select( Course.find(:all).map {|p| [p.title,p.id]},
2 )
%>
I DO GET 2nd option selected.
I am wondering, if I am doing anything wrong passing a variable as
"selected" attributed in options_for_select method.
Any help or suggestions would really be appreciated.
Thanks
- AJ
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---