Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails: form select

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:

like image 305
Max Avatar asked Jun 21 '09 04:06

Max


People also ask

What is form tag in Ruby on Rails?

The form_tag Rails helper generates a form withe the POST method by default, and it automatically renders the HTML that we were writing by hand before. Note: We can explicitly specify what HTTP verb to use for the form_tag if we want something other than POST .


1 Answers

<%= 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"
like image 123
Simone Carletti Avatar answered Nov 04 '22 11:11

Simone Carletti