我如何使用独angular兽作为“rails s”?

一个新的rails项目的gemfile显示:

# 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>' 

我以前在其他项目中使用过独angular兽,但是总是必须运行unicorn命令并指定一个configuration文件,这有点痛苦。 我想知道如何通过使用“rails s”来简单地使它工作…这可能吗?

它看起来像@Dogbert提到的unicorn-railsgem实际上可以用来使独angular兽的rails server处理程序。

只需在Gemfile包含gem "unicorn-rails" (以及for Rails 4.2.4, gem "rack-handlers" ),运行bundle install来安装gem,然后运行:

 $ rails server unicorn 

尽pipe安装了unicorn-rails ,Unicorn应该是默认的应用程序服务器,所以你也可以运行rails server ,它应该使用Unicorn(假设你的Gemfile没有Thin或Mongrel),在这种情况下,它们可能会发生冲突你可能想删除你不使用的)。

更好的select可能是直接运行独angular兽服务器。

 bundle exec unicorn -p 3000 # default port is 8080 
 gem 'rack-handlers' rails server unicorn 

我不认为有可能使用独angular兽作为“导轨”。 用这个 –

将gem'unicorn'添加到gem文件并运行bundle install。

然后运行以下任何命令 –

$ unicorn -p 3000

要么

$ unicorn_rails -p 3000

然而, Steven的答案是最简单的方法。

我通过rake任务在开发环境中运行unicorn

LIB /任务/ dev_unicorn.rake:

 task :server do # optional port parameter port = ENV['PORT'] ? ENV['PORT'] : '3000' puts 'start unicorn development' # execute unicorn command specifically in development # port at 3000 if unspecified sh "cd #{Rails.root} && RAILS_ENV=development unicorn -p #{port}" end # an alias task task :s => :server 

跑:

rake s

参考http://jing.io