Rails持续100年

Har*_*rry 1 arrays select ruby-on-rails

我怎样才能获得过去100年的动态数组?

 def years_options
    (100.years.ago.to_date..Date.today).map{ |year| year.strftime("%Y") }
 end
Run Code Online (Sandbox Code Playgroud)

返回大约36000个值,因为它返回year这两个日期之间的每一天.我怎么才能得到这些年的数组呢?

Rom*_*ain 5

你为什么不简单地说:

def years_options
    this_year = Date.today.year
    (this_year-100..this_year)
end
Run Code Online (Sandbox Code Playgroud)