The easiest way is to use the html attrs parameter, like this:
<%= form.select (:suchfeld,> [ [''Beschreibungen'',''description''],
> [''Headlines'',''headline'']]
, :selected => @varname> )
> %>
where "@varname" is the value that was selected before posting. That
var would be set in the controller, probably when you are grabbing the
post data.
On Jun 6, 1:46 am, "Jochen Kaechelin"
<giss...-Vg5pTm5GbeLoK6nBLMlh1Q@public.gmane.org>
wrote:> I have a search form in my navbar where a user can select in which
> area he wants to search. After clicking the submit-button the
> results get rendered but the previous selected area is no longer
> selected.
>
> <%= form.select (:suchfeld,
> [ [''Beschreibungen'',''description''],
> [''Headlines'',''headline'']] )
> %>
>
> I was able to re-fill the search-field wich the previous content
> doing the following:
>
> <%= form.text_field
> :suche,
> :name => "suche",
> :size => 25,
> :value => params[:suche].gsub(''
'','''')
> %>
>
> But how can I automatically add "selected" to a select-field to
> select the last selected item?
>
> Thanx
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---