I need to create a select box that goes from 1 to a number defined in a active record. This number will change.
So far I know I can create a select box like this:
<%= f.select :numbers, %w[1 2 3 4 5 6 7 8 9 10 ] %>
but what I need is something like this:
<%= f.select :numbers, %w[1..@user.number] %>
is there a way to create a nice dynamic select box in rails or do I need to manually create select tags in html with a for loop or something like that?
Thanks
You can turn a Range into an Array using the
to_amethod:Or you can hand
f.selectthe raw range and it will callto_afor you:From the fine manual:
And
options_for_selectsays:A Range is an Enumerable so both
f.selectcalls above should yield the same result.