[英]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: 我尝试过的
What I am doing right now: 我现在正在做什么:
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.