Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 我如何使用独角兽作为;rails s";?_Ruby On Rails_Ruby_Unicorn - Fatal编程技术网

Ruby on rails 我如何使用独角兽作为;rails s";?

Ruby on rails 我如何使用独角兽作为;rails s";?,ruby-on-rails,ruby,unicorn,Ruby On Rails,Ruby,Unicorn,新Rails项目的Gemfile显示: # Use unicorn as the app server gem 'unicorn' Usage: rails server [mongrel, thin, etc] [options] rails-help显示: # Use unicorn as the app server gem 'unicorn' Usage: rails server [mongrel, thin, etc] [options] 然而,做: rails s unic

新Rails项目的
Gemfile
显示:

# Use unicorn as the app server
gem 'unicorn'
Usage: rails server [mongrel, thin, etc] [options]
rails-help
显示:

# Use unicorn as the app server
gem 'unicorn'
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>'
/Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/rack-1.4.5/lib/rack/handler.rb:63:在'require'中:无法加载这样的文件--rack/handler/unicorn(LoadError)
来自/Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/rack-1.4.5/lib/rack/handler.rb:63:in'try_require'
来自/Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/rack-1.4.5/lib/rack/handler.rb:16:in'get'
来自/Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/rack-1.4.5/lib/rack/server.rb:272:in'server'
来自/Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/railties-3.2.13/lib/rails/commands/server.rb:59:in'start'
来自/Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/railties-3.2.13/lib/rails/commands.rb:55:in'block-in'
来自/Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/railties-3.2.13/lib/rails/commands.rb:50:in'tap'
来自/Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/railties-3.2.13/lib/rails/commands.rb:50:in`'
来自脚本/rails:6:in'require'
来自脚本/rails:6:in`'
我以前在其他项目中使用过unicorn,但总是要运行
unicorn
命令并指定一个配置文件,这有点麻烦。我想知道如何使用
rails s…

这可能吗?

看起来@Dogbert提到的gem实际上可以用来让Unicorn成为
rails服务器的
处理器

只需将
gem“unicorn rails”
(对于rails 4.2.4,
gem“rack handlers”
)包含在
gem文件中,运行
bundle install
安装gem,即可运行:

$ rails server unicorn

尽管安装了
unicorn rails
后,unicorn应该是默认的应用程序服务器,因此您也可以运行
rails server
,并且它应该使用unicorn(假设您的
Gemfile
中没有Thin或Mongrel,在这种情况下,它们可能会发生冲突,您可能希望删除不使用的应用程序).

更好的选择可能是直接运行unicorn服务器

bundle exec unicorn -p 3000 # default port is 8080

然而,史蒂文的回答是最简单的方法

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

lib/tasks/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


参考资料

我认为不可能将unicorn用作“rails s”。使用此项—

将gem“unicorn”添加到gem文件并运行bundle安装

然后运行以下任何命令-

$unicorn-p3000


$unicorn\u rails-p3000

我认为不能直接从
rails服务器
调用
unicorn
。看看这个-只需键入
unicorn
对我来说很有效,与
rails s
相同的击键次数,我发现gemfile建议使用“unicorn”而不是“unicorn\u rails”,这非常有趣。我还发现很有趣的是,这个网页上写着:“unicorn_rails是为了让rails机架前版本的用户更容易过渡。手册页鼓励rails 3用户改用普通unicorn。”你在哪个文件中看到了
unicorn
?我建议将
unicorn rails
gem添加到您的Gemfile中。对于rails 4.2.4,首先需要将
gem'rack handlers'
gem'unicorn'
一起添加到您的Gemfile中。使用rack handlers的另一个好处是它会自动加载config/unicorn.rb文件。如何增加工人?