简体   繁体   English

Rails:NameError:未初始化的常量 Rails::Application::YAML

[英]Rails: NameError: uninitialized constant Rails::Application::YAML

I was trying to deploy my application to heroku and got this error.我试图将我的应用程序部署到 heroku 并收到此错误。 I've been googling around and haven't see anyone with a YAML issue so thought I ask online.我一直在谷歌搜索并没有看到任何有 YAML 问题的人,所以我想我在网上询问。 Any help would be greatly appreciated任何帮助将不胜感激

 remote: -----> Preparing app for Rails asset pipeline
 remote:        Running: rake assets:precompile
 remote:        rake aborted!
 remote:        NameError: uninitialized constant Rails::Application::YAML
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:377:in `secrets'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/config/environments/production.rb:2:in `block in <top (required)>'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/railtie.rb:210:in `instance_eval'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/railtie.rb:210:in `configure'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/config/environments/production.rb:1:in `<top (required)>'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:598:in `block (2 levels) in <class:Engine>'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:597:in `each'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:597:in `block in <class:Engine>'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in `each'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in `tsort_each_child'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/config/environment.rb:5:in `<top (required)>'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:328:in `require'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:328:in `require_environment!'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:443:in `block in run_tasks_blocks'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'
 remote:        Tasks: TOP => environment
 remote:        (See full trace by running task with --trace)

Checking out my heroku logs查看我的 Heroku 日志

 2015-06-07T00:58:16.085579+00:00 heroku[slug-compiler]: Slug compilation started
 2015-06-07T00:58:16.085600+00:00 heroku[slug-compiler]: Slug compilation failed: failed to compile Ruby app

I am not quite sure what happened but I did a我不太确定发生了什么,但我做了一个

require 'yaml'

in my production.rb file and it worked.在我的 production.rb 文件中,它起作用了。 I do not know why it is working but will update if I find out.我不知道它为什么工作,但如果我发现会更新。

There is a bug in some versions of rails ( 4.2.1 and 4.2.2 that I know of) There is a missing require 'yaml' statement in the file in the first line of the error message.在某些版本的 rails(我知道的 4.2.1 和 4.2.2)中存在错误,错误消息第一行的文件中缺少require 'yaml'语句。 On a VPS you can insert it yourself, but I am not sure how to do it with Heroku.在 VPS 上,您可以自己插入,但我不确定如何使用 Heroku。 When I raised it on GitHub I was advised to upgrade to the next rails version...当我在 GitHub 上提出它时,我被建议升级到下一个 Rails 版本......

I added require 'yaml' to development.rb, production.rb and test.rb just to be on the safe side.为了安全起见,我在 development.rb、production.rb 和 test.rb 中添加了require 'yaml' Works fine now.现在工作正常。 Ruby 2.3.3 and Rails 4.2.0 Ruby 2.3.3 和 Rails 4.2.0

I had this issue when working on a legacy Rails 2.3 application with Docker .我在使用Docker 处理旧版Rails 2.3应用程序时遇到了这个问题。

I was running into this error whenever I start up the application using the command docker-compose up :每当我使用命令docker-compose up启动应用程序时,我都会docker-compose up这个错误:

web_1  | App 61 output: Error: The application encountered the following error: uninitialized constant YAML (NameError)
web_1  | App 61 output:     /workdir/config/environment.rb:13:in `block in <top (required)>'
web_1  | App 61 output:     /usr/local/bundle/bundler/gems/rails-3ce754b1f962/railties/lib/initializer.rb:113:in `run'
web_1  | App 61 output:     /workdir/config/environment.rb:3:in `<top (required)>'
web_1  | App 61 output:     config.ru:2:in `require'
web_1  | App 61 output:     config.ru:2:in `block in <main>'
web_1  | App 61 output:     /usr/local/bundle/gems/rack-1.4.7/lib/rack/builder.rb:51:in `instance_eval'
web_1  | App 61 output:     /usr/local/bundle/gems/rack-1.4.7/lib/rack/builder.rb:51:in `initialize'
web_1  | App 61 output:     config.ru:1:in `new'
web_1  | App 61 output:     config.ru:1:in `<main>'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/helper-scripts/rack-preloader.rb:101:in `eval'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/helper-scripts/rack-preloader.rb:101:in `preload_app'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/helper-scripts/rack-preloader.rb:189:in `block in <module:App>'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:378:in `run_block_and_record_step_progress'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/helper-scripts/rack-preloader.rb:188:in `<module:App>'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/helper-scripts/rack-preloader.rb:29:in `<main>'
web_1  | [ E 2020-10-25 17:55:09.8091 27/Tc age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /workdir: The application encountered the following error: uninitialized constant YAML (NameError)

Here's how I fixed it :这是我修复它的方法

On Rails 2.3 add the following in your config/environment.rb :Rails 2.3 中,在config/environment.rb添加以下内容:

require 'yaml'

On Rails 3.2 or Rails 4.2 , add the following in your config/application.rb :Rails 3.2Rails 4.2 上,在config/application.rb添加以下内容:

require 'yaml'

That's all.就这样。

I hope this helps我希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM