当我运行`rails server`时,如何让'puma'自动启动(就像Thin一样)

Mat*_*oti 29 ruby-on-rails puma

通常,当你运行rails server它时,启动Webrick.如果您安装'thin'宝石,那么'thin'会启动.我想用'puma'服务器做同样的事情.

我看到startrailties(lib/rails/commands)中的命令调用super,但我找不到'super'的各种选项.我还在'thin'中回顾了许多对Rails的引用.

我从2008年10月发现了一个名为"添加对脚本/服务器的精简支持.#488 [Bob Klosinski]"的Changelog条目,但该代码区域自该提交后发生了重大变化(a93ea88c0623b4f65af98c0eb55924c335bb3ac1).

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

Sim*_*ker 58

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

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

require 'rack/handler'
Rack::Handler::WEBrick = Rack::Handler.get(:puma)
Run Code Online (Sandbox Code Playgroud)

如果您使用,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
Run Code Online (Sandbox Code Playgroud)

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


Rya*_*dge 18

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

gem 'puma'
Run Code Online (Sandbox Code Playgroud)

然后运行'bundle',然后当你运行'rails server'时,将使用Puma.

  • echo'alias start_puma ="bundle exec puma -p 3000 -S~/puma -C config/puma.rb"'>>〜/ .bash_profile && source~/.bash_profile然后使用start_puma (2认同)

use*_*836 11

这适合我.Ruby 2.0.0 Rails 3.2.13 Puma 1.6.3

rails s puma
Run Code Online (Sandbox Code Playgroud)