Standalone ActiveRecord application can't find ActiveRecord

I need a standalone script to load models every two hours from an
external source. I copied code from the original Ruby on Rails (RoR)
application that works fine. The problem is that on my system, even
the simplest request produces an error: it can’t find ActiveRecord.
Example:

Here’s the simplified script:
#!/usr/bin/env ruby
require “rubygems”
gem “activerecord” #new version of ‘gem_require’
ActiveRecord::Base.establish_connection(:adapter =>
‘mysql’, :database => ‘sample’,
:username => ‘root’, :password => ‘pass’, :socket => ‘/tmp/
mysql.sock’)

Here’s the output:
ruby -w sample.rb
sample.rb:5: uninitialized constant ActiveRecord (NameError)

I get the same result putting the same code into irb.

But when I modify the last line of the script to simply “puts
$:” (i.e., print the list of loaded modules), here’s the list:
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/bin
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/bin
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib
/opt/local/lib/ruby/site_ruby/1.8
/opt/local/lib/ruby/site_ruby/1.8/i686-darwin8.8.1
/opt/local/lib/ruby/site_ruby
/opt/local/lib/ruby/vendor_ruby/1.8
/opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin8.8.1
/opt/local/lib/ruby/vendor_ruby
/opt/local/lib/ruby/1.8
/opt/local/lib/ruby/1.8/i686-darwin8.8.1

So ActiveRecord is sitting there. What am I doing wrong??
—Jim Gagne—

On 26 Oct 2007, at 22:18, Jim Gagne wrote:

gem "activerecord"             #new version of 'gem_require'

Try

require “rubygems”
require “active_record”

Fred