puma 初始值设定项不适用于 rails 4.2

puma initializer does not work with rails 4.2

我以前安装过很多次puma,从来没有出现过这个问题。我正在逐字遵循 heroku 的说明。我在里面创建了一个 Procfile

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

这里是配置文件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

当我通过 运行 rails srails s puma 启动服务器时,我得到

=> 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)

这是怎么回事,我该如何解决?我在开发中使用 sqlite3,在生产中使用 postgresql,但我在两种环境中都遇到了相同的错误。我正在使用 rails 4.2.0 和 ruby 2.2.0.

您的 Gemfile 中需要 gem 'puma'

编辑:puma.rb 不应位于初始值设定项文件夹中,而应位于配置文件夹之外。谢谢尼古拉

puma.rb 不应位于 initializers 文件夹中,而应位于 config 文件夹之外