Reputation: 1254
I have a form that has a drop-down that goes from 1 to 10. I need it to automatically select 10 when the page is loaded though.
I've tried this
f.select(:load_priority, options_for_select(1..10), :selected => 10)
But that still keeps the default on 1. How would I make it select 10 from the get-go?
Upvotes: 0
Views: 42
Reputation: 454
While using options_for_select, the default value can be passed as a second param.
Api guide url for reference, (http://apidock.com/rails/v4.2.1/ActionView/Helpers/FormOptionsHelper/options_for_select)
<%= f.select options_for_select((1..10), default) %>
Upvotes: 1
Reputation: 15781
You can do it like this:
<%= f.select(:load_priority, options_for_select((1..10), 10)) %>
Upvotes: 1