gpt4 book ai didi

ruby-on-rails - 未初始化的常量 TZInfo::InvalidTimezoneIdentifier (NameError) - Rails 4

转载 作者:行者123 更新时间:2023-12-01 22:37:31 25 4
gpt4 key购买 nike

我正在将 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”。然而,当 gem 被移除时,需求正在发生。

最佳答案

environment.rb 中初始化应用程序之前需要 tzinfo gem 为我解决了这个问题。并不能真正解释一切,但似乎可行

# adding this fixes the issue
require 'tzinfo'

# Initialize the rails application
RailsApp::Application.initialize!

编辑:似乎这是 Rails 的问题: https://github.com/rails/rails/issues/13553

关于ruby-on-rails - 未初始化的常量 TZInfo::InvalidTimezoneIdentifier (NameError) - Rails 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20713472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com