puma初始化程序不适用于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 `': undefined method `workers' for main:Object (NoMethodError) 

发生了什么,我该如何解决? 我在开发中使用sqlite3,在生产中使用postgresql,但我在两种环境中都得到了相同的错误。 我使用rails 4.2.0和ruby 2.2.0。

你需要在你的Gemfile中拥有gem’puma gem 'puma'

编辑:puma.rb不应位于initializers文件夹中,而应位于config文件夹中。 谢谢Nicolai

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