# Standalone ActiveRecord application can't find ActiveRecord

**URL:** <https://www.ruby-forum.com/t/standalone-activerecord-application-cant-find-activerecord/118440>\
**Category:** Rails\
**Created:** [October 26, 2007, 11:19pm UTC](https://www.ruby-forum.com/t/standalone-activerecord-application-cant-find-activerecord/118440 "2007-10-26T23:19:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_Gagne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@Jim\_Gagne](https://www.ruby-forum.com/u/Jim_Gagne)\
**Post date:** [October 26, 2007, 11:19pm UTC](https://www.ruby-forum.com/t/standalone-activerecord-application-cant-find-activerecord/118440/1 "2007-10-26T23:19:24Z")

</div>

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—

---

<div class="post-metadata">

**Author:** ![Jim\_Gagne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@Jim\_Gagne](https://www.ruby-forum.com/u/Jim_Gagne)\
**Post date:** [October 26, 2007, 11:23pm UTC](https://www.ruby-forum.com/t/standalone-activerecord-application-cant-find-activerecord/118440/2 "2007-10-26T23:23:29Z")

</div>

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

> ```
> gem "activerecord" #new version of 'gem_require'
> 
> ```

Try

require “rubygems”  
require “active\_record”

Fred
