Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - drop down (select) month / year

  1. How can I create in rails a drop down with all months in it?
  2. How do I create a drop down with a list of years beginning from current year and 8 years forward (2012, 2013... 2020)? Thanks.
like image 673
Noam B. Avatar asked Oct 21 '12 20:10

Noam B.


1 Answers

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) %>
like image 199
Alex Peattie Avatar answered Sep 21 '22 18:09

Alex Peattie