本文介绍了美洲狮初始化程序无法使用导轨4.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经多次安装过美洲狮,并且从未遇到这个问题。我遵循heroku的指示逐字。我在这里面创建了一个 Procfile

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

以下是配置文件puma.rb:



$ p $ lt; code> workers Integer(ENV ['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV ['MAX_THREADS'] || 5 )
线程threads_count,threads_count

preload_app!

rackup DefaultRackup
端口ENV ['PORT'] || 3000
环境ENV ['RACK_ENV'] || 'development'

on_worker_boot do
#Rails 4.1+的特定于工作人员的设置
#请参阅:https://devcenter.heroku.com/articles/deploying-rails-applications- with-the-puma-web-server#on-worker-boot
ActiveRecord :: Base.establish_connection
end

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

  =>启动Puma 
=> Rails 4.2.0应用程序从http:// localhost:3000
=>开始开发。为更多启动选项运行`rails server -h`
=> Ctrl-C关闭服务器
退出
/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。

解决方案

您需要 gem' puma'在您的Gemfile中



编辑:puma.rb不应位于initializers文件夹中,而应位于config文件夹的外部。感谢尼古拉


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.

解决方案

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

这篇关于美洲狮初始化程序无法使用导轨4.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 09:03