Rails 2.3.2 cannot find installed gems

I have a rails 2.3.2 application that uses crypt, RedCloth, mysql and
openrain-action_mailer_tls. As long as the gems are installed in the
@@frameworks_gems list things work. But when gems are not loaded in
@@frameworks_gems, the app fails left and right with “no such file”
errors on my gems.

I have traced into the search in gem_path_searcher.rb:78 and it
appears that the comparison

Dir[glob].select { |f| File.file? f.untaint }

will never find the required gem if the gem doesn’t have a specified
suffix.

eg:

When looking for the crypt gem (crypt-1.1.4)

glob = ‘/home/esmith/.gem/ruby/1.8/gems/crypt-1.1.4/{.}/crypt
{,.rb,.rbw,.so,.bundle,.dll,.sl,.jar}’

so Dir[glob].select { |f| …}

generates

f = ‘/home/esmith/.gem/ruby/1.8/gems/crypt-1.1.4/./crypt’

Passing this (untainted) to File.file? fails because “crypt” is not a
regular file.

This happens with all of the gems that are not in the @@framework_gems
list.

This behavior doesn’t change if they are loaded into vendor/gems. The
only way I can get the gems to load is to have them in the central gem
repository which I cannot access on my hosting service.

Am I missing something with this? Rails certainly appears to be.

On Fri, Mar 27, 2009 at 3:19 PM, Polydectes [email protected] wrote:

appears that the comparison
glob = '/home/esmith/.gem/ruby/1.8/gems/crypt-1.1.4/{.}/crypt

This happens with all of the gems that are not in the @@framework_gems
list.

This behavior doesn’t change if they are loaded into vendor/gems. The
only way I can get the gems to load is to have them in the central gem
repository which I cannot access on my hosting service.

Am I missing something with this? Rails certainly appears to be.

Polydectes, if you cannot access the central gem repository, then you’ll
need to unpack the gems into vendor. Thus, you’ll have to use one of
the following:

rake gems:unpack # unpacks the gem into
vendor/gems
rake gems:unpack:dependencies # unpacks the gems with their
dependencies
into vendor/gems

Also, their might be some gems that have native extensions after you
perform
the above. Thus, you
should perform the following within the root directory of your rails
application:

rake gems:build

Last but not least, here’s a great screen cast that talks about gems and
their dependencies:

http://media.railscasts.com/videos/110_gem_dependencies.mov

Good luck,

-Conrad

Conrad,

Thanks for the response.

Unfortunately, I’ve already unpacked the gems into the vendor/gems
folder. That didn’t work for some reason.

( "This behavior doesn’t change if they are loaded into vendor/gems.
The only way I can get the gems to load is to have them in the central
gem repository which I cannot access on my hosting service. ")

I have been able to get the application running under Mongrel;
however, I need to deploy on a server where they kill mongrel
processes after 2 minutes by policy. So I need to use fcgi through
rack to access the system.

When I test the access using dispatch.fcgi, I get a stack trace for
each gem that cannot be found. Each of the gems that cannot be found
is installed in my personal gem repository, and they have also been
unpacked into my applications vendor/gems folder.

I never had problems like this with 2.1.2 or 2.2.2, but for some
reason 2.3.2 just isn’t seeing my gems.

Eric.

On Sat, Mar 28, 2009 at 3:15 AM, Conrad T. [email protected]
wrote:

( "This behavior doesn’t change if they are loaded into vendor/gems.
is installed in my personal gem repository, and they have also been

so Dir[glob].select { |f| …}

rake gems:unpack # unpacks the gem into

Eric, after you unpacked the gems, are you requiring the gem into the
file(s)
that need it? For example,

require ‘rubygems’
require ‘RedCloth’

The above should be ‘redcloth’.

Can you post a stack trace? It will be a lot easier to figure out what
the problem is…

–Matt J.

On Fri, Mar 27, 2009 at 10:05 PM, EMS [email protected] wrote:

gem repository which I cannot access on my hosting service. ")

@@frameworks_gems list things work. But when gems are not loaded in

repository which I cannot access on my hosting service.
dependencies
Last but not least, here’s a great screen cast that talks about gems and
their dependencies:

http://media.railscasts.com/videos/110_gem_dependencies.mov

Good luck,

-Conrad

Eric, after you unpacked the gems, are you requiring the gem into the
file(s)
that need it? For example,

require ‘rubygems’
require ‘RedCloth’

or

require ‘rubygems’
require ‘crypt’

Note: In Ruby 1.9.1, one doesn’t need the following line:

      require 'rubygems'

-Conrad

I believe I’ve found the source of the problem.

When using a gem in Rails starting with 2.2.2, if the library name
isn’t an exact match for the gem name, then Rails can no longer find
the gem. Personally, I believe THIS IS A MAJOR PROBLEM WITH THE NEW
GEMS LOADING SCHEME!!! But that’s my personal opinion. It’s as if
the developers were taking a hint from Microsoft and taking away
important capabilities of the system which millions of people rely on
in an effort to make things “easier” for them. Bad Programmer! No
Donut!!!

The solution is to configure the gems in config/environment.rb and
include the library name. So for example, instead of just requiring
redcloth in your class files and modules, you also need to add:

config.gem “redcloth”, :lib => “RedCloth”

in your environment.rb

So the fix for my problem is to find the lib names for each of the
gems that are not being loaded. As I’ve shown above, RedCloth is the
name for redcloth and action_mailer_tls in my case is in the openrain-
action_mailer_tls library.

Now I just need to find the library names for crypt, rspec, and mysql.

Eric

On Sat, Mar 28, 2009 at 7:29 PM, EMS [email protected] wrote:

Donut!!!
So the fix for my problem is to find the lib names for each of the
gems that are not being loaded. As I’ve shown above, RedCloth is the
name for redcloth and action_mailer_tls in my case is in the openrain-
action_mailer_tls library.

Now I just need to find the library names for crypt, rspec, and mysql.

Eric

Yes, Brian Bates covers this in his screen cast on gem dependencies.
I really don’t think that it’s a major issue because anything that’s
installed
from github has the following syntax:

<user_name>-<project_name>

Thus, you might find a single project that has been forked two or more
times and the current scheme solves that problem. However, it would
be great to install a gem from gems.github.com using just the project
name as is the case with gems.rubyforge.org.

Next, it would definitely be better if the gem and library name were
identical so one wouldn’t have to hunt within the gem repository from
the correct library name. I guess this is something that gem makers
will have to address. Last but not least, the correct way to add the
RedCloth gem to your application is as follows:

config.gem “RedCloth”, :lib => “redcloth”

Good luck,

-Conrad