YAML.load 在 Rails 初始值设定项中永远不会返回
我试图在 Rails 3.1 应用程序初始化期间加载 yaml 配置文件,并且对 YAML.load 的调用永远不会返回。这是我的初始化程序文件:
STRIPE_CONFIG = begin
config = YAML.load(Rails.root.join('config', 'stripe.yml')) || {}
config = config[Rails.env] || {}
config.to_options
end
这是我的 stripe.yml 文件:
default: &default
api_key: test
public_key: test
development:
<<: *default
test:
<<: *default
production:
api_key: prod
public_key: prod
无论出于何种原因,YAML.load
调用永远不会返回。如果我执行堆栈跟踪,它似乎卡在 syck.rb 第 135 行上。有趣的是,我让应用程序在中断之前停留的时间越长,对第 135 行的调用就越多。
/Users/mhuggins/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/syck.rb:135:in `read'
/Users/mhuggins/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/syck.rb:135:in `read'
/Users/mhuggins/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/syck.rb:135:in `load'
/Users/mhuggins/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/syck.rb:135:in `load'
/Users/mhuggins/Sites/dating/config/initializers/stripe.rb:2:in `<top (required)>'
...
我也尝试过明确使用 Psych 而不是使用 Syck,但没有运气。 (它最终也会挂起。)
STRIPE_CONFIG = begin
require 'psych'
config = Psych.load(Rails.root.join('config', 'stripe.yml')) || {}
config = config[Rails.env] || {}
config.to_options
end
I'm trying to load a yaml config file during initialization of my Rails 3.1 app, and the call to YAML.load never returns. Here is my initializer file:
STRIPE_CONFIG = begin
config = YAML.load(Rails.root.join('config', 'stripe.yml')) || {}
config = config[Rails.env] || {}
config.to_options
end
And here is my stripe.yml file:
default: &default
api_key: test
public_key: test
development:
<<: *default
test:
<<: *default
production:
api_key: prod
public_key: prod
For whatever reason, the YAML.load
call never returns. If I perform a stack trace, it seems to be stuck on syck.rb line 135. The interesting thing is, the longer I let my app sit before breaking, the more calls to line 135 appear.
/Users/mhuggins/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/syck.rb:135:in `read'
/Users/mhuggins/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/syck.rb:135:in `read'
/Users/mhuggins/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/syck.rb:135:in `load'
/Users/mhuggins/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/syck.rb:135:in `load'
/Users/mhuggins/Sites/dating/config/initializers/stripe.rb:2:in `<top (required)>'
...
I've tried explicitly using Psych as well instead of using Syck, but with no luck. (It ends up hanging as well.)
STRIPE_CONFIG = begin
require 'psych'
config = Psych.load(Rails.root.join('config', 'stripe.yml')) || {}
config = config[Rails.env] || {}
config.to_options
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案会有点晚,但我刚才偶然发现了类似的问题;)
您可以使用
YAML::load_file
,它需要文件名作为参数。Answer will be kinda late, but I have stumbled upon similar problem just now ;)
You could use
YAML::load_file
, which expects filename as an argument.呃,显然我只需要显式读取该文件。我把这个: 改为
:
Ugh, apparently I just needed to explicitly read the file. I changed this:
to this: