开发者

Undefined method '>>' for class 'Date' in Rails 3 on Ruby 1.8.7/1.9.2

I'm running a Rails 3.0.0 application on Ruby 1.8.7-p174. Everything was going swimmingly until I tried to run some tests:

/Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb:9: undefined method `>>' for class `Date' (NameError)
from /Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/activesupport-3.0.0/lib/active_support/ruby/shim.rb:12:in `require'
from /Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/activesupport-3.0.0/lib/active_support/ruby/shim.rb:12
from /Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/actionpack-3.0.0/lib/abstract_controller.rb:6:in `require'
from /Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/actionpack-3.0.0/lib/abstract_controller.rb:6

I took a look into that Calculations class, noting that undef was being called with :>>. But Ruby 1.8.7 Dates don't have a >> method. I figured I'd wrap it with a condition: if respond_to?(:>>). Things broke further along this time:

/Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb:91:in `alias_method': undefined method `+' for class `Date' (NameError)
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb:91:in `<class:Date>'
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb:7:in `<top (required)>'
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/ruby/shim.rb:12:in `require'
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/ruby/shim.rb:12:in `<top (required)>'
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/actionpack-3.0.0/lib/abstract_controller.rb:6:in `require'

The second stack trace i开发者_StackOverflow社区s Ruby 1.9.2. I'm getting the same error with Ruby 1.9.2 without my respond_to? check as Ruby 1.8.7 with it.

I commented out my Date extensions in lib. This only occurs in the test environment.

Thoughts?


So this may not be the most helpful answer but it's all I've been able to determine so far.

The file in question: activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb removes the definitions of :>> as you saw. If the file is require twice, the second loading of that file will fail due to the method no longer being defined on the Date class.

So why is this file being required twice? That I'm really not sure of. I've seen that the protection against this can be buggy (if you'd call it a bug, it may just be a limitation) when you specify the file with a full path once and then another time you depend on the LOAD_PATH having the correct folder in it to find you file that way.

I'd look through your code and see what is requiring either rails/all or activesupprt/railstie and hopefully you'll see two separate places that look slightly different. Also see if you're mucking with the LOAD_PATH anywhere between the two places.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜