When I am trying to deploy an rails application to Heroku, I am getting this error:
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. This happens only when I deploy to Heroku.
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. Or at least set all variables used by 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.
For me, the application was not using ActiveRecord, but there were still references to it. Because require "active_record/railtie"
was commented out, it broke on production.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.