You can pass a second argument to the options_for_select
method to pre-select the value. For example, assuming your model object is represented by an instance variable called @object
, you can pass in @object.endMonth
as the second parameter to your options_for_select
.:
<%= f.select :endMonth, options_for_select([['January' ,'1'],['February' ,'2'], ['March', '3'],['April' ,'4'], ['May', '5'],['June' ,'6'],['July' ,'7'], ['August', '8'],['September' ,'9'], ['October', '10'],['November' ,'11'], ['December', '12']], @object.endMonth), class: "list-select" %>
Note: the @object.endMonth
value must resolve to the same data type as the option value - in this case the number representing the month. See the Rails Guide for details.