Reputation: 378
I have rails form with date_select
field in rails application. by default it shows 10 years from now in drop down list, but I want to access particular year in drop down. How can I do that in rails application?
Here is what I tried and I got error:
undefined method `merge' for 2000..2040:Range
<div class="field columns large-3">
<%= form.label :planned_start_date, :class=>"required" %>
<%= form.date_select :planned_start_date, Date.today.year-20 .. Date.today.year+20, :include_blank => true, order: [:day, :month, :year], class: 'select-date' %>
</div>
Upvotes: 0
Views: 42
Reputation: 1920
Accordingly to documentation date_select
accepts these options:
:start_year - Set the start year for the year select. Default is Date.today.year - 5 if you are creating new record. While editing existing record, :start_year defaults to the current selected year minus 5.
:end_year - Set the end year for the year select. Default is Date.today.year + 5 if you are creating new record. While editing existing record, :end_year defaults to the current selected year plus 5.
So just replace your range to proper options hash as:
<%= form.date_select :planned_start_date, start_year: Date.today.year - 20, end_year: Date.today.year + 20, :include_blank => true, order: [:day, :month, :year], class: 'select-date' %>
And this should work
Upvotes: 1