问题
I'm in the process of upgrading a Rails 3.2 app to Rails 4.1. Whenever I try to start the console or server though, I come across this error:
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)>'
...
Not really sure what's causing it and wondered if anyone has any advice. I tried this in irb and didn't encounter any problems (an error is raised as it should be):
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 includes:
ruby "2.0.0"
gem "rails", "~> 4.1.0.beta1"
gem 'tzinfo-data'
Edit (some more info):
It seems as if the inclusion of the gem 'tzinfo-data' might be messing something up? When the gem is in the gemfile, in seems as if 'tzinfo' isn't ever getting required during the RailsApp::Application.initialize!
call in environment.rb. However, when the gem is removed, the require is happening.
回答1:
Requiring the tzinfo
gem before initializing the app in environment.rb
fixes the issue for me. Doesn't really explain everything, but seems to work
# adding this fixes the issue
require 'tzinfo'
# Initialize the rails application
RailsApp::Application.initialize!
Edit: Seems this was a problem with Rails: https://github.com/rails/rails/issues/13553
回答2:
This worked for me:
gem uninstall tzinfo
#select 'All versions'
gem install tzinfo
rails c
来源:https://stackoverflow.com/questions/20713472/uninitialized-constant-tzinfoinvalidtimezoneidentifier-nameerror-rails-4