是否可以在Rails中的两个日期之间创建一个月份列表

问题描述:

我正在尝试创建一个页面来显示每个月的链接列表,分为几年。这几个月需要在两个日期之间,今天和第一个条目的日期。

I am trying to create a page to display a list of links for each month, grouped into years. The months need to be between two dates, Today, and The date of the first entry.

我在砖墙上,我不知道如何创建这个。

I am at a brick wall, I have no idea how to create this.

任何帮助都将被大规模的评价

Any help would be massively appriciated

Regards
Adam

Regards Adam

只需将你想要的内容放在一个范围循环中,并使用Date :: MONTHNAMES数组,这样

Just put what you want inside a range loop and use the Date::MONTHNAMES array like so

(date.year..laterdate.year).each do |y|
   mo_start = (date.year == y) ? date.month : 1
   mo_end = (laterdate.year == y) ? laterdate.month : 12

   (mo_start..mo_end).each do |m|  
       puts Date::MONTHNAMES[m]
   end
end