0

I have a local gem present that I can execute from script, shows up in my Gemfile.lock as installed, and returns true in rails console with "Gem.available?("< gem name >").

However, when I try to require this gem in order to call a script that relies on it through rails console (or rake task or a controller), I get "`require': cannot load such file -- < gem name> ".

RubyGems Environment:

- RUBYGEMS VERSION: 1.8.25
- RUBY VERSION: 1.9.3 (2013-02-06 patchlevel 385) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/www-data/.rvm/gems/ruby-1.9.3-p385
- RUBY EXECUTABLE: /home/www-data/.rvm/rubies/ruby-1.9.3-p385/bin/ruby
- EXECUTABLE DIRECTORY: /home/www-data/.rvm/gems/ruby-1.9.3-p385/bin
- RUBYGEMS PLATFORMS:
  - ruby
  - x86_64-linux
- GEM PATHS:
  - /home/www-data/.rvm/gems/ruby-1.9.3-p385
  - /home/www-data/.rvm/gems/ruby-1.9.3-p385@global
- GEM CONFIGURATION:
  - :update_sources => true
  - :verbose => true
  - :benchmark => false
  - :backtrace => false
  - :bulk_threshold => 1000
- REMOTE SOURCES:
  - http://rubygems.org

irb:

$ irb
1.9.3-p385 :001 > require '<gem name>'
=> true

console:

RAILS_ENV=production rails console
Loading production environment (Rails 3.2.3)
1.9.3-p385 :001 > require '<gem name>'
LoadError: cannot load such file -- <gem name>

Is the console operating in a seperate environment? %x( which ruby ) would say no.. the gem also appears in my gem list for both bundle, Gemfile.lock, and %( gem list ) in the console.

  • What you need to require is not always the same as the Gem name: http://stackoverflow.com/questions/132867/i-have-a-gem-installed-but-require-gemname-does-not-work-why The Gem's documentation should tell you how to require it. – Ross Allen Aug 07 '13 at 22:20
  • It would be in this case. I'm using require '< gem name >' at the top of a script that runs just fine using the same gem. Something in Rails isn't seeing this gem as installed.. I cannot even execute that working script using %x(). – Ryan C. Moon Aug 07 '13 at 22:24
  • Is the gem defined in the production group in your Gemfile? – Philip Hallstrom Aug 08 '13 at 01:02
  • Negative, sir. Its at the bottom of the Gemfile outside of any groups. – Ryan C. Moon Aug 08 '13 at 02:04

1 Answers1

0

In case anyone runs into this, the trick is a bug with Bundler.

  1. Declare the gem in your Gemfile without path (" gem '< gem name >','< version >' ")
  2. Copy your gem into vendor/cache/
  3. run "bundler install --no-cache".

Even though you have told it not to use the cache it will find the gem, install it, and make it available to Rails.