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:
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 .
<%= 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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With