Forum: Ruby on Rails can't find gems in /vendor/gems/ after modifying load_paths

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sarah A. (Guest)
on 2009-02-13 18:42
I'm picking up a Rails app that is using a lot of older gems.  We're
using Rails 2.0.2 and planning to move to to Rails 2.3 along with
upgrading the the dependencies.  However, in the meantime, we're moving
servers around and adding new folks to the dev team, so I thought it
wise to "freeze" the gems.  I'm trying to follow the methodology
described here:
http://errtheblog.com/posts/50-vendor-everything
and here:
http://wiki.joyent.com/shared:kb:installing-rails

Unfortunately, the gems don't seem to be found.

Here's what I did... I had all the old gems installed to ~/.gems and all
the tests passed.  Then I unpacked the gems into /vendor/gems

cd ~/rails/vendor/gems
gem unpack exifr
gem unpack rmagick
gem unpack tzinfo
gem unpack uuidtools

I added the following to config/enviroment.rb inside
Rails::Initializer.run do |config|

config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/**"].map do |dir|
  File.directory?(lib = "#{dir}/lib") ? lib : dir
end
# print out my load_paths for debugging
config.load_paths.each do |p|
  puts p
end

and later:
require 'rubygems'
gem 'exifr', '=0.10.6'
gem 'uidtools', '=1.0.2'
gem 'rmagick', '=1.15.8'
gem 'tzinfo', '=0.3.5'

Here's what happens:
$rake test:units
(in /home/sallen/rails)
/home/sallen/rails/test/mocks/development
/home/sallen/rails/app/controllers/
/home/sallen/rails/app
/home/sallen/rails/app/models
/home/sallen/rails/app/controllers
/home/sallen/rails/app/helpers
/home/sallen/rails/config
/home/sallen/rails/lib
/home/sallen/rails/vendor
/home/sallen/rails/config/../vendor/rails/railties/lib/../builtin/rails_info/
/home/sallen/rails/vendor/gems/exifr-0.10.6/lib
/home/sallen/rails/vendor/gems/tzinfo-0.3.5/lib
/home/sallen/rails/vendor/gems/rmagick-1.15.8/lib
/home/sallen/rails/vendor/gems/uuidtools-1.0.2/lib
rake aborted!
Could not find RubyGem exifr (= 0.10.6)

(See full trace by running task with --trace)
$ ls vendor/gems/
exifr-0.10.6  rmagick-1.15.8  tzinfo-0.3.5  uuidtools-1.0.2

I must be missing something basic.  Any ideas?

Thanks in advance,
Sarah
Matt J. (Guest)
on 2009-02-14 22:10
(Received via mailing list)
On Feb 13, 11:42 am, Sarah A. <removed_email_address@domain.invalid>
wrote:
> Here's what I did... I had all the old gems installed to ~/.gems and all
>
> gem 'exifr', '=0.10.6'
> gem 'uidtools', '=1.0.2'
> gem 'rmagick', '=1.15.8'
> gem 'tzinfo', '=0.3.5'
>
>

Take a careful look at the errtheblog article - you should be using
require, not gem here.
The gem statements only add the gem directories to the load_path.

In the long run, you should definitely switch over to using
config.gem, but that isn't an
option with Rails 2.0.3.

BTW, even changing to 'require's is still going to leave you with
problems, as RMagick's
native component hasn't been built yet. I don't know of any easy way
to do it in your
situation. You might want, for the short term, to just leave the 'gem'
lines in your environment
and keep the gem packages for the gems you need around. That way, the
code will complain
loudly if the gems needed aren't installed.

--Matt J.
Sarah A. (Guest)
on 2009-02-14 23:07
Matt J. wrote:
> Take a careful look at the errtheblog article - you should be using
> require, not gem here.
> The gem statements only add the gem directories to the load_path.

Changing to 'require' got past that error.  I still don't understand why
it failed to load since I had requires elsewhere that just didn't
specify the version.  Where would I look up the syntax reference for
'gem' and 'require' ?  I'm not really clear where those come from.  I
see 'require' documented here: http://www.rubygems.org/read/chapter/3
but it doesn't reference the version argument and I don't see where
'gem' is documented.

> In the long run, you should definitely switch over to using
> config.gem, but that isn't an
> option with Rails 2.0.3.
I'll give that a look when we upgrade.

> BTW, even changing to 'require's is still going to leave you with
> problems, as RMagick's
> native component hasn't been built yet. I don't know of any easy way
> to do it in your
> situation.
Thanks for the warning.

> You might want, for the short term, to just leave the 'gem'
> lines in your environment
> and keep the gem packages for the gems you need around. That way, the
> code will complain
> loudly if the gems needed aren't installed.
Hmmm... so it seems that 'gem' just declares that the code depends on a
gem, and 'require' actually loads the library?

Thanks so much!
Sarah
Sean M. (Guest)
on 2009-02-26 23:07
Hello everyone,

Rails 2.2.2
Gems  1.8

When I add this to my config/environment.rb file my app fails to start.

config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/**"].map do |dir|
  File.directory?(lib = "#{dir}/lib") ? lib : dir
end


Does anyone know why that might be happening?

Thank You
Matt J. (Guest)
on 2009-02-27 22:58
(Received via mailing list)
DON'T DO THAT. That's from a very old tip that no longer applies to
current (2.2+) versions of Rails. See this link:
http://api.rubyonrails.org/classes/Rails/Configura...

--Matt J.

On Feb 26, 4:07 pm, Sean M. <removed_email_address@domain.invalid>
Sean M. (Guest)
on 2009-02-27 23:22
Matt:  Thank you for your reply.  I have put this in the environment.rb
file and my app fails to start?

config.gem 'cyu-ar_mailer', :lib => 'ar_mailer', :source =>
'http://gems.github.com'


Thanks
Matt J. (Guest)
on 2009-03-01 01:21
(Received via mailing list)
"Fails to start" is not very helpful - what error message do you get?
It'll be helpful to know what version of Rails you're running, and the
output of
'rake gems'. If that errors out, try 'rake gems --trace' to get a
detailed error.

--Matt J.

On Feb 27, 4:22 pm, Sean M. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.