我如何使用独角兽作为“rails"?
一个新的 Rails 项目的 Gemfile
显示:
A new Rails project's Gemfile
shows:
# Use unicorn as the app server
gem 'unicorn'
rails s --help
显示:
Usage: rails server [mongrel, thin, etc] [options]
然而,正在做:
rails s unicorn
我明白了:
/Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/rack-1.4.5/lib/rack/handler.rb:63:in `require': cannot load such file -- rack/handler/unicorn (LoadError)
from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/rack-1.4.5/lib/rack/handler.rb:63:in `try_require'
from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/rack-1.4.5/lib/rack/handler.rb:16:in `get'
from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/rack-1.4.5/lib/rack/server.rb:272:in `server'
from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/railties-3.2.13/lib/rails/commands/server.rb:59:in `start'
from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/railties-3.2.13/lib/rails/commands.rb:55:in `block in <top (required)>'
from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
我过去在其他项目中使用过 unicorn,但总是不得不运行 unicorn
命令并指定一个配置文件,这有点麻烦.我想知道如何通过使用 rails s...
I've used unicorn in the past on other projects, but always had to run the unicorn
command and specify a config file which is a bit of a pain. I am wondering how I can just simply make it work by using rails s...
这可能吗?
它看起来像 unicorn-rails
@Dogbert 提到的 gem 实际上可以用来使 Unicorn 成为 rails server
处理程序.
It looks like the unicorn-rails
gem that @Dogbert mentioned can actually be used to make Unicorn the rails server
handler.
只需在 Gemfile
中包含 gem "unicorn-rails"
(对于 Rails 4.2.4,gem "rack-handlers"
), 运行 bundle install
安装 gem,然后可以运行:
Simply include gem "unicorn-rails"
(and for Rails 4.2.4, gem "rack-handlers"
) in your Gemfile
, run bundle install
to install the gem, then you can run:
$ rails server unicorn
虽然一旦安装了 unicorn-rails
,Unicorn 应该是默认的应用服务器,所以你也可以只运行 rails server
并且它应该使用 Unicorn(假设你不t 在您的 Gemfile
中也有 Thin 或 Mongrel,在这种情况下,它们可能会发生冲突,您可能希望删除您不使用的那些).
Although once unicorn-rails
is installed, Unicorn should be the default app server so you could also just run rails server
and it should use Unicorn (assuming you don't also have Thin or Mongrel in your Gemfile
, in which case they may conflict and you might want to remove the ones you're not using).