Rails 3周显示

时间:2011-05-06 15:59:04

标签: ruby-on-rails-3

如何在轨道中显示一年中剩余的几周?

2 个答案:

答案 0 :(得分:2)

这里显然没有明确指定格式,但是这样的事情会显示当年剩下的每周的索引:

(Date.today.cweek..52).each { |w| puts w }

有关类似问题,请参阅Looping through weeks of the year in Ruby (Sinatra)

答案 1 :(得分:1)

(Date.today.cweek...Date.today.end_of_year.cweek)

修改

(Date.today.cweek...Date.today.end_of_year.cweek).each_slice(2) do |weeks|
  puts weeks.join("-")
end