Ruby-on-rails 当我运行“rails server”(就像 Thin 一样)时,如何让“puma”自动启动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13365940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:00:54  来源:igfitidea点击:

How do I get 'puma' to start, automatically, when I run `rails server` (like Thin does)

ruby-on-railspuma

提问by Matt Scilipoti

Normally, when you run rails serverit starts Webrick. If you install the 'thin' gem, then 'thin' starts instead. I would like to do the same thing with the 'puma' server.

通常,当您运行rails server它时,它会启动 Webrick。如果您安装“瘦”gem,则改为“瘦”。我想对“美洲狮”服务器做同样的事情。

I see that the startcommand within railties (lib/rails/commands) calls super, but I can't find what the various options for 'super' are. I have also reviewed many references to Rails within 'thin'.

我看到startrailties (lib/rails/commands) 中的命令调用 super,但我找不到“super”的各种选项是什么。我还在“瘦”中查看了许多对 Rails 的引用。

I found a Changelog entry entitled "Added Thin support to script/server. #488 [Bob Klosinski]" from Oct. of 2008, but that code area has changed significantly since that commit (a93ea88c0623b4f65af98c0eb55924c335bb3ac1).

我从 2008 年 10 月发现了一个名为“Added Thin support to script/server.#488 [Bob Klosinski]”的变更日志条目,但自那次提交(a93ea88c0623b4f65af98c0eb55924c335bb3ac1)以来,该代码区域发生了重大变化。

If someone could direct me to the right section of code, that would be very helpful.

如果有人可以将我引导到正确的代码部分,那将非常有帮助。

回答by Simon Woker

After some digging, I've found this answer: https://stackoverflow.com/a/14911994/604526

经过一番挖掘,我找到了这个答案:https: //stackoverflow.com/a/14911994/604526

To make Puma the default, paste this code into script/rails above require 'rails/commands':

要使 Puma 成为默认值,请将此代码粘贴到上面 require 'rails/commands' 的脚本/rails 中:

require 'rack/handler'
Rack::Handler::WEBrick = Rack::Handler.get(:puma)

Puma is the default server now if you use rails s

如果您使用,Puma 现在是默认服务器 rails s

rails s
=> Booting Puma
=> Rails 3.2.12 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Connecting to database specified by database.yml
Puma 1.6.3 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://0.0.0.0:3000

Rails 4

导轨 4

With Rails 4 you simply have to add the puma-gem to the Gemfile. (Tested with Rails 4.0.2 and Puma 2.6.0)

使用 Rails 4,您只需将 puma-gem 添加到 Gemfile。(使用 Rails 4.0.2 和 Puma 2.6.0 测试)

回答by Ryan Sandridge

At least in Rails 4, you just need to add the following to your Gemfile

至少在 Rails 4 中,您只需要将以下内容添加到 Gemfile 中

gem 'puma'

then run 'bundle', and then when you run 'rails server' and Puma will be used.

然后运行'bundle',然后当你运行'rails server'时,就会使用Puma。

回答by user2110836

This works for me. Ruby 2.0.0 Rails 3.2.13 Puma 1.6.3

这对我有用。红宝石 2.0.0 导轨 3.2.13 美洲狮 1.6.3

rails s puma

回答by RocketR

Puma documentationsuggests that you prepend #\ -s pumato your config.ru.

Puma 文档建议您#\ -s pumaconfig.ru.