On 5 October 2010 14:06, PalaniKannan K <[email protected]> wrote:
>
>
> On 5 October 2010 11:14, PalaniKannan K <[email protected]> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to