views:

3509

answers:

2

I have a form that I want to show a drop-down menu that shows a selection for the person's age. The range is from 18 to 99. How do I do it with the form select helper? Isn't it something like:

<%= f.select :age, ['18'..'99'] %>

+6  A: 
<%= select(@object, :age, (18..99).to_a) %>

select is defined in FormOptionsHelper so the interface is a bit different.

Ben Hughes
+5  A: 
<%= f.select :age, (18..99) %>

The problem was that ['18'..'99'] doesn't return what you expect. ['18'..'99'] is not a range but a 1-size array where the only one item has value ['18'..'99'].

>> ['18'..'99'].class
=> Array
>> ['18'..'99'].size
=> 1
>> ['18'..'99'].first
=> "18".."99"
Simone Carletti