Forum: Ruby on Rails "selected" in

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
9fa0e9901902a1eb76217f33bd15c4a2?d=identicon&s=25 Jochen Kaechelin (Guest)
on 2007-06-06 10:47
(Received via mailing list)
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

<%= (:suchfeld,
   [ ['Beschreibungen','description'],
   ['Headlines','headline']] )

I was able to re-fill the search-field wich the previous content
doing the following:

<%= form.text_field
   :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?

Cdd31341b14358e7a7128f8302c8bb97?d=identicon&s=25 tresudek (Guest)
on 2007-07-23 00:42
(Received via mailing list)
The easiest way is to use the html attrs parameter, like this:
 <%= (: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.
This topic is locked and can not be replied to.