Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rack/Sinatra LoadError: cannot load such file

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:

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:

➜  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):

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?

like image 751
Kevin Swallow Avatar asked Jun 19 '12 22:06

Kevin Swallow


1 Answers

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.

like image 160
keithcelt Avatar answered Sep 19 '22 23:09

keithcelt