轨。尝试设置beginning_of_week时错误的参数数量错误

时间:2012-08-20 21:10:08

标签: ruby-on-rails ruby activesupport

我遵循了这个Railscast:http://railscasts.com/episodes/213-calendars-revised

似乎没有很多人收到错误,但我收到ArgumentError: wrong number of arguments (1 for 0)这个电话:

first = date.beginning_of_month.beginning_of_week(START_DAY)

即便如此,如果我在控制台中尝试它,它也会给我同样的错误。

Date.today.beginning_of_month.beginning_of_week(start_day = :sunday)
Date.today.beginning_of_month.beginning_of_week(start_day = 'sunday')
Date.today.beginning_of_month.beginning_of_week('sunday')
Date.today.beginning_of_month.beginning_of_week(:sunday)

我已经用Google搜索并查看了文档,它似乎应该可行。我甚至试过require 'active_support/all,但它总是返回false

如何将星期的开头设为星期日?

1 个答案:

答案 0 :(得分:2)

我无法访问截屏视频。但是当我在控制台模式(而不是IRB)中运行Rails时:

rails c(Ruby v1.9.3p194)

Loading development environment (Rails 3.2.8)
1.9.3p194 :001 > Date.today.beginning_of_month.beginning_of_week(start_day = :sunday)
 => Sun, 29 Jul 2012 
1.9.3p194 :002 > 

也许是你的Ruby或Rails版本,我正在运行:rails(3.2.8)?

从3.2.1开始,似乎添加了参数(一周的哪一天开始):

http://apidock.com/rails/v3.2.1/Date/beginning_of_week