Dear All, Anybody knows to keep the selected option as alive even after "submit" in collection_select. -- With Regards Palani Kannan. K -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
PalaniKannan K
2010-Oct-05 13:06 UTC
Re: Keep collection_select as selected after "submit"
On 5 October 2010 11:14, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Dear All, > > Anybody knows to keep the selected option as alive even after "submit" in > collection_select. >Hi, I found the method. If I use like this I can keep as live. <%= collection_select(@table, "gm", @pop, "col1", "col1", :prompt => true, *:selected => params[:gm]*) %> The bold marked content, I inserted to my script and the selected value remains.> > -- > With Regards > Palani Kannan. K > >-- With Regards Palani Kannan. K -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 October 2010 14:06, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 5 October 2010 11:14, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> Dear All, >> >> Anybody knows to keep the selected option as alive even after "submit" in >> collection_select. > > Hi, > > I found the method. If I use like this I can keep as live. > > <%= collection_select(@table, "gm", @pop, "col1", "col1", :prompt => true, > :selected => params[:gm]) %> > > The bold marked content, I inserted to my script and the selected value > remains.I think it is not considered good practice to directly reference params in the view, as that means that the view is directly dependent on the way the controller action was called. It might be better in the controller action to say @selected_item = params[:gm] and then in the view use :selected = @selected_item. It amounts to the same thing but achieves better separation of the different bits of code. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.