Forum: Ruby on Rails Are Ducks Hibernating ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F16def8015a7562a285c65a14be48540?d=identicon&s=25 Mathieu Chappuis (Guest)
on 2005-12-21 09:50
(Received via mailing list)
Dears,

Remembering last value in a select box don't work for me as :

Controller :
   @years=(1970..2005).to_a

Form:
<%= select_tag "year", options_for_select( (2001..2005).to_a,
@params[:year] ) %>

I had to write

<%= select_tag "year", options_for_select( (2001..2005).to_a,
@params[:year].to_i ) %>

for it works.

Not important, but I'm curious why..

Seasons Greetings,
953c18019bceaa294ae0429bef6ab388?d=identicon&s=25 Norman Timmler (Guest)
on 2005-12-21 10:59
(Received via mailing list)
Am Mittwoch, den 21.12.2005, 09:49 +0100 schrieb Mathieu Chappuis:
>
> I had to write
>
> <%= select_tag "year", options_for_select( (2001..2005).to_a,
> @params[:year].to_i ) %>
>
> for it works.

The Array items are compared to the selected value using the '=='
comparator. You are comparing Integer == String, what result in false.
This topic is locked and can not be replied to.