puma initializer does not work with rails 4.2

可紊 提交于 2019-12-24 03:53:23

问题


I have installed puma many times before and have never had this problem. I am following heroku's instructions verbatim. I have created a Procfile with this inside:

web: bundle exec puma -C config/puma.rb

Here is the configuration file puma.rb:

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['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
  # Worker specific setup for Rails 4.1+
  # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
  ActiveRecord::Base.establish_connection
end

When I start the server by running rails s or rails s puma i get

=> Booting Puma
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/david/projects/abc/config/initializers/puma.rb:1:in `<top (required)>': undefined method `workers' for main:Object (NoMethodError)

What is happening and how do I fix it? I am using sqlite3 in development and postgresql in production but i get the same error in both environments. I am using rails 4.2.0 and ruby 2.2.0.


回答1:


You need to have gem 'puma' in your Gemfile

Edit: The puma.rb should not be located in the initializers folder, but outside in the config folder. Thanks Nicolai




回答2:


The puma.rb should not be located in the initializers folder, but outside in the config folder



来源:https://stackoverflow.com/questions/32259490/puma-initializer-does-not-work-with-rails-4-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!