John
John

Reputation: 1323

rails drop down to select the years from current year to past four years

How do I create a drop down with a list of years beginning from current year and 4 years backward (2015, 2014... 2013)? and by default it should show the current year.

Upvotes: 2

Views: 1161

Answers (2)

Haider Ali
Haider Ali

Reputation: 800

Agreed with Pavan but this would be much better

<%= select_year(Date.today, :start_year => Date.today.year, :end_year =>  Date.today.year-4) %>

Upvotes: 3

Pavan
Pavan

Reputation: 33542

You can use select_year. Something like below will do

<%= select_year(Date.today, :start_year => Date.today.year, :end_year => 2012) %>

Upvotes: 2

Related Questions