Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

activesupport - Uninitialized Constant TZInfo::InvalidTimezoneIdentifier (NameError) - Rails 4

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...