Rails - drop down (select) month / year

For the months:

<%= select_month(Date.today) %>

(the Date.today argument will default it to the current month - use select_month(1) to default to January)

For the years:

<%= select_year(Date.today, :start_year => Date.today.year, :end_year => 8.years.from_now.years) %>

A small addition to @alex answer,

By default, if you do

select_month(Date.today, field_name: 'start')

it will generate select tag with name “date[start]”. If you want it to be something other than date[], add :prefix option, like this:

select_month(Date.today, field_name: 'start', prefix: 'timer')

This will render select tag with name “timer[start]”.


<%= f.select :month, 1..12 %>

<%= f.select :year, Date.today.year.. 8.years.from_now.year %>