7

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?

Phrogz
  • 296,393
  • 112
  • 651
  • 745
Kevin Swallow
  • 145
  • 1
  • 1
  • 5
  • Out of curiosity, why would you require Pony only when the form is posted? Why not just require it once at app startup? (I don't use Bundler or Heroku, and so cannot advise you on what may or may not be wrong with your gem install and/or load library.) – Phrogz Jun 19 '12 at 22:20
  • 2
    Also, note that under Ruby 1.9 you should not need to `require 'ruby gems'`; it's part of the installation. Have you tried putting just `require 'pony'` before `require 'sinatra'` in the simplest possible app? – Phrogz Jun 19 '12 at 22:24
  • Thank you, Phrogz. I originally required pony at the top with the other requires, and moved it to match an example I had seen. Requiring it later allows the app to run until post is called. The require 'ruby gems' was a leftover from trying to manually add the gem to the load path, which I may not have done correctly. I should have deleted it. I am trying to do an even simpler app starting with Pony and it hasn't blown up yet, so maybe that will bear fruit. I'll post the results. – Kevin Swallow Jun 20 '12 at 15:31
  • Great; update if/when your pared-down test app explodes. :) (And please forgive my iPhone changing `rubygems` to `ruby gems` _sigh_). – Phrogz Jun 20 '12 at 15:43

2 Answers2

14
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.

keithcelt
  • 415
  • 4
  • 9
  • Thank you, keithcelt! 'require "bundler/setup"' fixed it. I have discontinued working with the pared-down app at least for now. I expect it would have worked until I did something that split my gems as before. – Kevin Swallow Jun 20 '12 at 21:25
0

I write down name of the gem (pony - in my case) in Gemfile - and it starts to work. Just open Jemfile - and write down words jem "pony" in the new line I get the following paste2.org/6hVxHXKH

fenek
  • 11
  • 4
  • Could you add a little more detail - show exactly how you changed your gemfile? – Aaron V Jan 16 '19 at 06:24
  • Just open Jemfile - and write down words jem "pony" in the new line I get the following https://paste2.org/6hVxHXKH – fenek Jan 16 '19 at 23:36
  • Thanks - please add the instructions to the answer itself. It should include a code snippet to at least give the readers an example of what you're suggesting – Aaron V Jan 17 '19 at 20:13