Hi, I am using collection_select to build a drop down list. I would like to have the current value selected. How can I do that? My current code is straight from the example in Pragmatic Programmers book [2nd ed, p480] copying here for reference. <% @users = User.find(:all, :order => "name" ) form.collection_select(:name, @users, :id, :name) %> I went through the api docs and found that there is a way to do this using selected_value, but an example would be much appreciated. raj --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rajkumar S wrote:> I am using collection_select to build a drop down list. I would like > to have the current value selected. How can I do that?> <%> @users = User.find(:all, :order => "name" ) > form.collection_select(:name, @users, :id, :name) > %>Can you pass in :selected => my_favorite_id ? -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks a lot for your reply! On 11/28/06, Phlip <phlip2005-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Rajkumar S wrote: > > > I am using collection_select to build a drop down list. I would like > > to have the current value selected. How can I do that? > > > <%> > @users = User.find(:all, :order => "name" ) > > form.collection_select(:name, @users, :id, :name) > > %> > > Can you pass in :selected => my_favorite_id ?Did this, but that does not seems to help :( raj --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---