Rack / Sinatra LoadError:无法加载此类文件

时间:2022-10-13 00:22:26

I'm trying to build an app using Sinatra, Ruby, rack, haml, pony and SendGrid, with git and RVM for deployment on Heroku. The app is a blog variant that should send out an email with commentary submitted on a form. On my local server, when the form submits I get the following error:

我正在尝试使用Sinatra,Ruby,rack,haml,pony和SendGrid构建一个应用程序,使用git和RVM在Heroku上进行部署。该应用程序是一个博客变体,应发送一封电子邮件,其中包含在表单上提交的评论。在我的本地服务器上,当表单提交时,我收到以下错误:

LoadError at /
cannot load such file -- pony
file: tools.rb location: require line: 314
BACKTRACE
(expand)
/Users/Kevin/prog/ruby/Sinatra/Noobs/noobs.rb in block in <top (required)>
  require 'pony'

When run on Heroku, form submittal results in an internal server error. The 'cannot load such file' error suggests that the file is not on the gem path, but if I understand correctly, the OS disagrees:

在Heroku上运行时,表单提交会导致内部服务器错误。 '无法加载此类文件'错误表明该文件不在gem路径上,但如果我理解正确,操作系统不同意:

➜  noobs git:(master) ✗ bundle show pony
/Users/Kevin/.rvm/gems/ruby-1.9.3-p194@noobs/gems/pony-1.4

➜  noobs git:(master) echo $GEM_PATH
/Users/Kevin/.rvm/gems/ruby-1.9.3-p194@noobs:/Users/Kevin/.rvm/gems/ruby-1.9.3-p194@global

Here is the code where pony is required (noobs.rb):

这是需要pony的代码(noobs.rb):

require 'rubygems'
require 'sinatra'
require 'haml'
require "sinatra/reloader" if development?  

# ...

post '/' do
  require 'pony'
  Pony.mail(:from => params[:name] + "<" + params[:contact] + ">",

What do I need to do to get pony to work?

我需要做些什么来让小马工作?

1 个解决方案

#1


11  

require "bundler/setup"

Will probably fix your error.

可能会修复你的错误。

Since you are using Bundler with Sinatra you need to require Bundler for the bundled gems to work. You probably have your gems split between Bundler and your gemset. If you have Sinatra and Haml in your gemset but Pony in your Gemfile you will see a LoadError.

由于您正在使用Bundler与Sinatra,因此您需要Bundler才能使捆绑的gem工作。您可能在Bundler和gemset之间拆分了宝石。如果您的宝石集中有Sinatra和Haml,但Gemfile中有Pony,您将看到LoadError。

#1


11  

require "bundler/setup"

Will probably fix your error.

可能会修复你的错误。

Since you are using Bundler with Sinatra you need to require Bundler for the bundled gems to work. You probably have your gems split between Bundler and your gemset. If you have Sinatra and Haml in your gemset but Pony in your Gemfile you will see a LoadError.

由于您正在使用Bundler与Sinatra,因此您需要Bundler才能使捆绑的gem工作。您可能在Bundler和gemset之间拆分了宝石。如果您的宝石集中有Sinatra和Haml,但Gemfile中有Pony,您将看到LoadError。