我试图将我的应用程序部署到heroku并遇到此错误。我一直在谷歌搜索,没有看到任何人有YAML问题,所以我想在网上问。任何帮助将不胜感激
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)
检查我的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
答案 0 :(得分:7)
我不太确定发生了什么,但我做了
require 'yaml'
在我的production.rb文件中,它工作正常。我不知道它为什么会起作用但如果我发现它会更新。
答案 1 :(得分:1)
某些版本的rails存在错误(我知道4.2.1和4.2.2)错误消息的第一行文件中缺少require 'yaml'
语句。在VPS上你可以自己插入,但我不知道如何使用Heroku。
当我在GitHub上提出它时,我被建议升级到下一个rails版本......
答案 2 :(得分:0)
我将require 'yaml'
添加到development.rb,production.rb和test.rb只是为了安全起见。现在工作正常。 Ruby 2.3.3和Rails 4.2.0
答案 3 :(得分:0)
在使用 Docker 的旧版 Rails 2.3 应用程序时,我遇到了这个问题。
每当我使用命令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)
这是我修复的方式:
在 Rails 2.3 上,在您的config/environment.rb
中添加以下内容:
require 'yaml'
在 Rails 3.2 或 Rails 4.2 上,在您的config/application.rb
中添加以下内容:
require 'yaml'
仅此而已。
我希望这会有所帮助