Ruby 中的 .next_month 问题
在我当地的环境中一切正常。当我上传到服务器时,我不断收到内部服务器错误。我已经注释掉了我的代码,直到找到有问题的行:
dateObj = dateObj.next_month #Problem Child
这是完整的代码:
def makeCal(dateObj)
cal = Hash.new
months = 0
while months < 12
# #pass dateobj to build array
array = buildArray(dateObj)
# #save array to hash with month key
monthName = Date::MONTHNAMES[dateObj.mon]
cal[monthName] = array
# #create new date object using month and set it to the first
date = dateObj.month.to_s + '/' + 1.to_s + '/' + dateObj.year.to_s
dateObj = Date.strptime(date, "%m/%d/%Y")
puts dateObj.kind_of? Date
dateObj = dateObj.next_month #Problem Child
months = months + 1
end
cal
end
本地 ruby -v:
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
远程 ruby -v:
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
关于如何解决这个问题的任何想法?
更新:
173.26.190.206 - - [03/Sep/2011 10:40:17] "POST /calendar " 500 30 0.0020
这是来自 nginx 的
,这是堆栈跟踪:
NoMethodError - undefined method `next_month' for #<Date: 4911549/2,0,2299161>:
./main.rb:82:in `makeCal'
./main.rb:120:in `POST /calendar'
我插入了以下行:puts dateObj.kind_of?日期
和我得到的一切都是真的。所以我的 dateObj 是 Date 类型
In my local enviroment everything works fine. When I upload to my server, I keep getting an Internal Server Error. I've commented out my code until I found the offending line which is:
dateObj = dateObj.next_month #Problem Child
Here is the complete code:
def makeCal(dateObj)
cal = Hash.new
months = 0
while months < 12
# #pass dateobj to build array
array = buildArray(dateObj)
# #save array to hash with month key
monthName = Date::MONTHNAMES[dateObj.mon]
cal[monthName] = array
# #create new date object using month and set it to the first
date = dateObj.month.to_s + '/' + 1.to_s + '/' + dateObj.year.to_s
dateObj = Date.strptime(date, "%m/%d/%Y")
puts dateObj.kind_of? Date
dateObj = dateObj.next_month #Problem Child
months = months + 1
end
cal
end
And ruby -v locally:
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
and ruby -v remotely:
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
Any ideas on how to solve this?
UPDATE:
173.26.190.206 - - [03/Sep/2011 10:40:17] "POST /calendar " 500 30 0.0020
That's from nginx
and this is the stack trace:
NoMethodError - undefined method `next_month' for #<Date: 4911549/2,0,2299161>:
./main.rb:82:in `makeCal'
./main.rb:120:in `POST /calendar'
I inserted the line: puts dateObj.kind_of? Date
and I get all true. So my dateObj is of kind Date
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您缺少
顺便说一句,如果您需要的只是
next_month
,您可以使用Date#>>
是核心库的一部分。编辑:
要获取该月的第一天,您可以使用:
It seems that you lack
BTW, if all you need from it is
next_month
, you can useas
Date#>>
is part of core library.Edit:
For getting the first of the month, you can use: