1

I'm a little confused... I have Rails 2.3.2 running on my server after upgrading from 2.1.1 I get the following error on my mongrel clusters when they try to start:

Exception `Gem::LoadError' at /usr/lib/ruby/site_ruby/1.8/rubygems.rb:578 - Could not find RubyGem activerecord-mysql-adapter (>= 0)

What is this caused by? I've done:

gem install mysql

...with all the various path-specific magic to make it install. A google search reveals some similar problems but no apparent resolution. Any ideas?

More Information:

Versions: Rails 2.3.2 (via gem), RubyGems 1.3.4 (via gem), Ruby 1.8.5 (via yum), Linux 2.6.18-xen (CentOS 5.2).

MySQL adapter (gem install mysql) is 2.7.

The odd thing is that if I remove the mysql adapter (gem uninstall mysql) I would expect it to revert to the built-in (albeit slow...?) MySQL adapter. It doesn't act any differently.

  • The presence or absence of the mysql gem is irrelevant; that is *not* the ActiveRecord adapter. The AR adapter for MySQL is not a separate gem, the Gem::LoadError is a red herring. – womble Jun 15 '09 at 09:53
  • OK -- that makes sense. Thanks for your help! I'm going to call this closed since the problem is gone and I can't reproduce it now. – Andrew Flanagan Jun 15 '09 at 14:50

1 Answers1

2

The underlying cause of this is Rails 2.3's feature of allowing external gems to provide connection adapters, rather than having them all bundled. The gory details are in activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb if you're interested, but the long and the short of it is that the first thing that establish_connection will try to do is load a gem, and if that fails to do a "traditional" require (which will load the built-in mysql adapter).

Signalling the "failure" is done by raising LoadError, and here's where things get annoying. Rubygems has it's own LoadError class (Gem::LoadError) and I think this is where the problem is coming from, in that activerecord isn't properly detecting that the (expected) failure has occured, and so is bombing out instead of just trying to load the connection adapter locally.

Bodgy back that you'll probably regret doing in the future is to change activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb line 72 to:

rescue LoadError, Gem::LoadError

The proper way of fixing this is to work out what's gone wrong in your environment to cause this (since it obviously doesn't break for everyone). My first guesses would be that you're running an old version of RubyGems (line 578 of rubygems.rb in version 1.3.3 has nothing to do with load errors, for example), or a strange (possibly out-of-date) version of Ruby. I'd make sure you're running an up-to-date Rubygems (Rails 2.3 requires at least 1.3.1 to run right, which I'm thinking might be what you're hitting) and that your Ruby version isn't too out there (use 1.8.6 or 1.8.7, and I'd be wary of using 1.9 in your situation).

If you're running all that OK and the problem persists, give full and complete details of your system (OS, distro, source of Ruby/rubygems (package, from source, etc), versions of all the above, any customisations) and someone can run the problem to ground. As it stands you've given no information that helps anyone to help track the problem down.

womble
  • 95,029
  • 29
  • 173
  • 228
  • I tried updating Rails, RubyGems, etc. and had no luck. I ended up reverting to a backup image for the site and it worked. It simply doesn't seem to be related to the older versions of the tools or anything in the rails application configuration itself. Very odd -- I have no idea. – Andrew Flanagan Jun 15 '09 at 06:32