views:

243

answers:

2

I have a bunch of config.gem statements in my environment.rb file:

config.gem "fastercsv", :version => "~>1.5.0"
  config.gem "parseexcel", :version => "~>0.5.2"
  config.gem "geokit", :version => "~>1.4.1"
  config.gem "facebooker", :version => "~>1.0.50"

...

If I do "rake gems:install" then I get this issue: rake aborted! no such file to load -- fastercsv

Well...i know there is no such file to load because I am trying to install it. I suspect this may result from the location of my require. I have a module in my lib directory:

module SmartContactsImporter

  require 'fastercsv'
  require 'parseexcel'
...

Maybe Rails doesn't like me requiring a gem there but it seems silly since there is nothing wrong with having your module depend on a gem. Any ideas on how to solve this issue?

UPDATE Turns out that this issue also occured with mechanize, geokit, and the list is continuing. It's a bit strange that config.gem doesn't work pretty easily out of the box. FYI I'm not freezing my gems.

+2  A: 

If you leave out the require in SmartContactsImporter this should work (config.gem "fastercsv" will do the require for you).

You can work around it when a require is needed in environment.rb with a:

begin
  require "rack/cache"
rescue LoadError
  STDERR.puts "not loaded rack/cache: #{$!}"
end

This is ugly but it does do the trick.

cwninja
A: 

You shouldn't require inside your module, config.gem will require it for you.

There's also a related issue with config.gem where it will attempt to require a dependent gem that is not yet installed whilst installing the gems, but this doesn't appear to be the case yet.

Ryan Bigg