我正在将Rails 3.2应用程序升级到Rails 4.1。每当我尝试启动控制台或服务器时,我都会遇到这个错误:
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.1.0.beta1/lib/active_support
/core_ext/time/zones.rb:70:in `rescue in find_zone!': uninitialized constant TZI
nfo::InvalidTimezoneIdentifier (NameError)
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.1.0.beta1/lib/a
ctive_support/core_ext/time/zones.rb:55:in `find_zone!'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.1.0.beta1/lib/a
ctive_support/railtie.rb:20:in `block in <class:Railtie>'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.1.0.beta1/lib/rails/
initializable.rb:30:in `instance_exec'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.1.0.beta1/lib/rails/
initializable.rb:30:in `run'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.1.0.beta1/lib/rails/
initializable.rb:55:in `block in run_initializers'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each
_strongly_connected_component'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_
component_from'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_c
onnected_component'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:180:in `each'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_
component'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.1.0.beta1/lib/rails/
initializable.rb:54:in `run_initializers'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.1.0.beta1/lib/rails/
application.rb:285:in `initialize!'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.1.0.beta1/lib/rails/
railtie.rb:194:in `public_send'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.1.0.beta1/lib/rails/
railtie.rb:194:in `method_missing'
from C:/sites/RailsApp/config/environment.rb:5:in `<top (required)>'
...
不确定是什么导致了它,并想知道是否有人有任何建议。我在irb中尝试了这个并没有遇到任何问题(应该出现错误):
irb(main):001:0> require 'active_support/core_ext/time/zones'
=> true
irb(main):002:0> Time.find_zone!('good')
ArgumentError: Invalid Timezone: f
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.1.0.beta1/lib/a
ctive_support/core_ext/time/zones.rb:71:in `rescue in find_zone!'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.1.0.beta1/lib/a
ctive_support/core_ext/time/zones.rb:55:in `find_zone!'
from (irb):3
from C:/Ruby200/bin/irb:12:in `<main>'
Gemfile包括:
ruby "2.0.0"
gem "rails", "~> 4.1.0.beta1"
gem 'tzinfo-data'
修改(更多信息):
似乎包含gem'tzinfo-data'可能会搞砸了什么?当gem在gemfile中时,好像在environment.rb中的RailsApp::Application.initialize!
调用期间不需要'tzinfo'。然而,当宝石被移除时,需要发生。
答案 0 :(得分:8)
在tzinfo
初始化应用之前要求environment.rb
gem修复了我的问题。没有真正解释一切,但似乎工作
# adding this fixes the issue
require 'tzinfo'
# Initialize the rails application
RailsApp::Application.initialize!
编辑: 似乎这是Rails的一个问题: https://github.com/rails/rails/issues/13553
答案 1 :(得分:-1)
这对我有用:
gem uninstall tzinfo
#select 'All versions'
gem install tzinfo
rails c