hi friends, i have used select_tag for country selection. in this select_tag i want to make one of the option by default selected. how to do it? plz somebody help me. code: ====.rhtml ------- <%= select_tag "country", options_from_collection_for_select(@country,"id","name",@selected) %> controller ---------- @country = City.find_by_sql("select * from countries") -- 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 -~----------~----~----~----~------~----~------~--~---
b.hutchison-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-11 00:28 UTC
Re: problem with select_tag
Did you ever figure this one out? I''ve been struggling with the same question. Its easy with the model forms (form_for, form.select) but not for non-model forms that I can see. Any help? Anyone? - Brian On Feb 19, 1:59 am, trupti <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> hi friends, > > i have usedselect_tagfor country selection. > in thisselect_tagi want to make one of the option by default selected. > how to do it? > plz somebody help me. > > code: > ====> .rhtml > ------- > <%=select_tag"country", > options_from_collection_for_select(@country,"id","name",@selected) %> > > controller > ---------- > @country = City.find_by_sql("select * from countries") > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
trupti wrote:> .rhtml > ------- > <%= select_tag "country", > options_from_collection_for_select(@country,"id","name",@selected) %>please modify "@selected" to "selected_value=@country.id)". -- 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 -~----------~----~----~----~------~----~------~--~---
yang jindong wrote:> trupti wrote: > >> .rhtml >> ------- >> <%= select_tag "country", >> options_from_collection_for_select(@country,"id","name",@selected) %> > > > please modify "@selected" to "selected_value=@country.id)".i''m sorry.there''s a mistake.please delete the ")". -- 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 -~----------~----~----~----~------~----~------~--~---