简体   繁体   English

Puma:无法加载应用程序:NameError:未初始化的常量

[英]Puma: Unable to load application: NameError: uninitialized constant

When I am trying to deploy an rails application to Heroku, I am getting this error: 当我尝试将Rails应用程序部署到Heroku时,出现此错误:

Puma starting in single mode...
2017-02-27T15:08:03.908788+00:00 app[web.1]: * Version 3.7.0 (ruby 2.3.1-p112), codename: Snowy Sagebrush
2017-02-27T15:08:03.908789+00:00 app[web.1]: * Min threads: 5, max threads: 5
2017-02-27T15:08:03.908790+00:00 app[web.1]: * Environment: production
2017-02-27T15:08:05.942041+00:00 app[web.1]: ! Unable to load application: NameError: uninitialized constant Api::V1::AController
2017-02-27T15:08:05.942133+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.3.0/bin/puma)
2017-02-27T15:08:05.942266+00:00 app[web.1]: NameError: uninitialized constant Api::V1::AController

Here is the link to the full log 这是完整日志的链接

If I try to run the following code on my dev environment, everything works just fine: 如果我尝试在我的开发环境上运行以下代码,则一切正常:

bundle exec puma -C config/puma.rb

I ran rails on my local machine using the -e production flag and it runs ok, no error appears. 我使用-e production标志在本地计算机上运行了rails,它运行正常,没有出现错误。 This happens only when I deploy to Heroku. 仅当我部署到Heroku时才会发生这种情况。

puma.rb puma.rb

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
    ActiveRecord::Base.establish_connection
end

What I've tried: 我尝试过的

  1. Created a new instance on Heroku just to be sure there was not a problem with the current instance 为了确保当前实例没有问题,在Heroku上创建了一个新实例
  2. Tested multiple versions of Puma 测试了多个版本的Puma
  3. Checked development.rb and production.rb to see what was different 检查development.rbproduction.rb以查看有什么不同

What I am doing right now: 我现在正在做什么:

  1. Going through each commit to find what changed in the app and try to find the cause of the app 通过每次提交查找应用程序中发生的更改,并尝试查找导致应用程序的原因

I believe I am overcomplicating the problem... Any thoughts on this? 我相信我使问题变得过于复杂...对此有何想法?

Try to reproduce this problem on your local machine by setting all environmental variables to the same values as on Heroku. 通过将所有环境变量设置为与Heroku相同的值,尝试在本地计算机上重现此问题。 Or at least set all variables used by puma: 或至少设置puma使用的所有变量:

RAILS_ENV=production RACK_ENV=production WEB_CONCURRENCY=1 RAILS_MAX_THREADS=5 bundle exec puma -C config/puma.rb

Also I've noticed that you are using threads. 我也注意到您正在使用线程。 Is it on purpose? 是故意的吗? I mean ruby ecosystem is not famous for thread safety. 我的意思是红宝石生态系统并不是以线程安全而闻名。 Try changing RAILS_MAX_THREADS to 1 and bump WEB_CONCURRENCY to higher number. 尝试将RAILS_MAX_THREADS更改为1,并将WEB_CONCURRENCY更改为更高的数字。

For me, the application was not using ActiveRecord, but there were still references to it. 对我而言,该应用程序未使用ActiveRecord,但仍然有对其的引用。 Because require "active_record/railtie" was commented out, it broke on production. 因为注释了require "active_record/railtie" ,所以生产中断了。

暂无
暂无

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

相关问题 Ruby PUMA错误:“无法加载应用程序:NameError:未初始化的常量Service :: Resolv” - Ruby PUMA error: “Unable to load application: NameError: uninitialized constant Service::Resolv” NameError:未初始化的常量 Capistrano::Puma - NameError: uninitialized constant Capistrano::Puma NameError:未初始化的常量和 LoadError:无法自动加载常量 - NameError: uninitialized constant and LoadError: Unable to autoload constant 控制器中无法加载的模块-NameError:未初始化的常量 - Cant load module in controller - NameError: uninitialized constant Rails NameError:初始加载时未初始化的常量 - Rails NameError: uninitialized constant on initial load Rails:NameError:未初始化的常量 Rails::Application::YAML - Rails: NameError: uninitialized constant Rails::Application::YAML 未初始化的常数MyApp :: Application :: GeoKit(NameError) - uninitialized constant MyApp::Application::GeoKit (NameError) `load_missing_constant':未初始化的常量AuthenticatedTestHelper(NameError) - `load_missing_constant': uninitialized constant AuthenticatedTestHelper (NameError) Ruby on Rails Tutorial by Michael - Chapter -2 Toy App - Puma 发现了这个错误:未初始化的常量 ApplicationController (NameError) - Ruby on Rails Tutorial by Michael - Chapter -2 Toy App - Puma caught this error: uninitialized constant ApplicationController (NameError) 未初始化的常量TestFactories(NameError) - uninitialized constant TestFactories (NameError)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM