Reputation: 22264
I need a drop down list that just shows the years from 1990 to 2014.
I've tried:
<%= select_tag "year", [1900..2014] %>
But I get:
<select id="year" name="year">[1900..2014]</select>
Any suggestions?
Upvotes: 0
Views: 136
Reputation: 15526
Use ()
instead of []
, like this:
<%= select_tag "year", options_for_select((1900..2014).to_a) %>
The expression [1900..2014]
represents an array whose only element is a range.
Calling to_a
on a 1..10 range returns [1,2,3,'...','etc']
.
Edit: oops, select_tag, unlike the f.select
you use insde form_for
blocks doesn't automatically convert array into option tags, so you need to use options_for_select
. @dimuch just noted that.
Upvotes: 1
Reputation: 12818
Try to add options_for_select
<%= select_tag "year", options_for_select(1900..2014) %>
Upvotes: 1