Rack/Sinatra LoadError: cannot load such file

11,457
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.

Share:
11,457
Kevin Swallow
Author by

Kevin Swallow

Updated on June 08, 2022

Comments

  • Kevin Swallow
    Kevin Swallow almost 2 years

    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?