Rails 关于没有 Puma 的开发模式

Rails on development mode without Puma

在我为生产模式安装 Puma 后,它不应该 运行 在我的本地机器上,但是 Puma 正在以开发模式启动并在片刻后停止且没有错误。

$ rails server
=> Booting Puma
=> Rails 4.2.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[8707] Puma starting in cluster mode...
[8707] * Version 3.1.0 (ruby 2.3.0-p0), codename: El Niño Winter Wonderland
[8707] * Min threads: 1, max threads: 6
[8707] * Environment: development
[8707] * Process workers: 1
[8707] * Phased restart available
[8707] * Listening on tcp://localhost:3000
[8707] Use Ctrl-C to stop

看起来是捆绑程序问题: github.com/puma/puma/issues/983

这不是一个真正的解决方案,但对于那些使用 Puma 生产模式服务器并希望使用 WEBrick 在本地机器开发模式下工作的人来说,这是一个很好的解决方案。这个解决方案基于 mrvncaragay 的想法

1。 将你 Gemfile 分成 3 个文件:

Gemfile_base
Gemfile_development
Gemfile_production

in Gemfile_base 包括所有 gem 非测试、开发和生产。没有理由包含 source 'https://rubygems.org' 或 Gemfile_development 或 Gemfile_production 文件。 在 Gemfile_development 中仅包括测试和开发 gems 在 Gemfile_production 中仅包括生产 gems

2。 将Gemfile中的所有行替换为:

source 'https://rubygems.org'

gemfiles = [ 'Gemfile_base', 'Gemfile_development' ]
#gemfiles = [ 'Gemfile_base', 'Gemfile_production' ]
gemfiles.each do |gemfile|
  instance_eval File.read(gemfile)
end

3。 部署到生产服务器

4。 添加 Gemfile 到 .gitignore 文件

#bundle Puma in development mode bad wordaround
Gemfile

5。 从源代码控制中取消跟踪 Gemfile

git rm --cached Gemfile

6. 从以下位置更改生产服务器中 Gemfile 的提交行:

source 'https://rubygems.org'

gemfiles = [ 'Gemfile_base', 'Gemfile_development' ]
#gemfiles = [ 'Gemfile_base', 'Gemfile_production' ]
gemfiles.each do |gemfile|
  instance_eval File.read(gemfile)
end

至:

source 'https://rubygems.org'

#gemfiles = [ 'Gemfile_base', 'Gemfile_development' ]
gemfiles = [ 'Gemfile_base', 'Gemfile_production' ]
gemfiles.each do |gemfile|
  instance_eval File.read(gemfile)
end