Search code examples
ruby-on-railsrubyhamlsimple-form

How do I order a collection in decreasing order?


I am building a form to select a year from 2010 to current year.

= f.input :duration do
    = f.select :duration, options_for_select(2010..@currentyear.to_i)

and it gives me a drop down list:

Dropdown

But if I try to do it in descending order (like 2015, 2014, 2013, 2012, 2011, 2010),

options_for_select(@currentyear.to_i..2010)

I get a blank drop down menu. What do I do?


Solution

  • Change this line

    options_for_select(@currentyear.to_i..2010)
    

    to

    options_for_select((2010..@currentyear.to_i).to_a.reverse)