无法加载这样的文件——rack/handler/puma [英] cannot load such file -- rack/handler/puma
问题描述
当我使用 rackup 和 puma 启动 Sinatra 应用程序时出现错误.我的 config.ru
文件如下所示:
I get an error when I start my Sinatra application with rackup and puma. My config.ru
file looks like this:
#\ -s puma
require './controller/main.rb'
run Sinatra::Application
所以当我现在使用 rackup 时,我得到这个错误:
So when I now use rackup I get this error:
/home/username/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/handler.rb:76:in `require': 无法加载此类文件 --机架/处理程序/美洲狮(LoadError)
/home/username/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/handler.rb:76:in `require': cannot load such file -- rack/handler/puma (LoadError)
我使用 ruby 1.9.3p392 (2013-02-22 修订版 39386) [i686-linux]
I use ruby 1.9.3p392 (2013-02-22 revision 39386) [i686-linux]
我的第一个想法是我忘记安装 puma,或者 puma 以某种方式坏了.所以我尝试了:
My first thought was that I forgot to install puma, or puma is broken in some way. So I tried:
puma -v
puma version 2.0.1
我直接用 ruby 启动它:
And I start it directly with ruby:
ruby controller/main.rb
Puma 2.0.1 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:4567
我发现了这个 puma issue,但我没有找到真正的解决方案.
And I found this puma issue but I didn't find a real solution.
为什么会发生这种情况?
Why id this happening?
我该如何解决这个问题?
How can I fix this?
推荐答案
对 gem 进行沙箱处理,以免它们与 Rubygems 安装的那些混淆.
Sandbox the gems so they don't get mixed up with those installed by Rubygems.
使用
rm -rf .bundle Gemfile.lock bin vendor
然后运行
bundle install --binstubs --path vendor
这会将所有 gem 安装到 vendor/RUBY-ENGINE/VERSION/
并将所有可执行文件安装到 bin
目录中.这些与通过 gem
命令安装的那些是分开的,后者将是系统范围的.
This installs all gems into vendor/RUBY-ENGINE/VERSION/
and all executables into the bin
dir. These are separate from the ones installed via the gem
command, which will be system wide.
使用 bundle exec
运行,但由于使用了 --binstubs
命令,您可以改为运行
Run using bundle exec
, but since the --binstubs
command was used you can instead run
bin/rackup config.ru
通过使用 bundle exec
或 bin/
中的可执行文件之一,您告诉 Bundler 只使用 it 安装.如果您使用 Bundler 安装了 Puma,那么它将使用 Bundler 安装的机架安装 Puma 处理程序.但是,您可能会安装 Rubygems 的另一个版本的 Rack(通过 gem install rack -r
),没有有处理程序.为了得到正确的,沙箱你的项目的 gems 并始终运行 bin/
目录中的东西.如果您需要 ruby
命令,请使用 bundle exec ruby...
,Bundler 将为项目加载正确的 gem.
By using bundle exec
or one of the executables from bin/
you're telling Bundler to only use the gems that it installed. If you installed Puma with Bundler then it will install the Puma handler with the Rack that Bundler installed. But, you'll probably have another version of Rack installed by Rubygems (via gem install rack -r
) that doesn't have the handler. To get the right one, sandbox your project's gems and always run stuff from the bin/
directory. If you need the ruby
command then use bundle exec ruby…
and Bundler will load the correct gems for the project.
我现在对每个项目都这样做,并且只在系统范围内需要它们时才通过 gem install...
安装 gem.它还确保您不会错过 Gemfile 中的任何 gem,因为您的系统上已经有了它们 - 部署时不会出现令人讨厌的惊喜!
I do this with every project now and only install gems via gem install…
if I need them system wide. It also makes sure you don't miss any gems out of the Gemfile because you had them already available on your system - no nasty surprises on deployment!
这篇关于无法加载这样的文件——rack/handler/puma的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!