# Active Record not found

**URL:** <https://rubytalk.org/t/active-record-not-found/38758>\
**Category:** ruby-talk\
**Created:** [29 June 2007 20:34 UTC](https://rubytalk.org/t/active-record-not-found/38758 "2007-06-29T20:34:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gray\_Bowman](https://avatars.discourse-cdn.com/v4/letter/g/74df32/32.png) [@Gray\_Bowman](https://rubytalk.org/u/Gray_Bowman)\
**Post date:** [29 June 2007 20:34 UTC](https://rubytalk.org/t/active-record-not-found/38758/1 "2007-06-29T20:34:53Z")

</div>

I'm new to ruby, so I may have this all wrong. I'm trying to use  
activerecord to manage database functions for a small script I'm  
writing. I've installed the activerecord gem, and verified it's in the  
list of local gems.

require 'net/http'  
require 'rubygems'  
gem 'activerecord'

ActiveRecord::Base.establish\_connection(  
&nbsp;&nbsp;:adapter =\> 'mysql',  
&nbsp;&nbsp;:host =\> 'localhost',  
&nbsp;&nbsp;:username =\> 'root',  
&nbsp;&nbsp;:password =\> '',  
&nbsp;&nbsp;:database =\> 'app\_development')

class Thing \< ActiveRecord::Base  
end

when I run I get the error:  
app/gatherer.rb:5: uninitialized constant ActiveRecord (NameError)

I've tried running from Aptana, the One-Click install and Instantrails.  
I get the same error in each. I'm thinking I must be doing something  
wrong.

Any guidance is appreciated.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Bira](https://avatars.discourse-cdn.com/v4/letter/b/c89c15/32.png) [@Bira](https://rubytalk.org/u/Bira)\
**Post date:** [29 June 2007 20:39 UTC](https://rubytalk.org/t/active-record-not-found/38758/2 "2007-06-29T20:39:22Z")

</div>

What happens if you replace "gem 'activerecord'" with "require 'activerecord'"?

> **···**
>
> On 6/29/07, Gray Bowman \<gray.bowman@gmail.com\> wrote:
> 
> > when I run I get the error:  
> > app/gatherer.rb:5: uninitialized constant ActiveRecord (NameError)
> 
> --  
> Bira
> 
> > **[Computaria Explícita](http://compexplicita.blogspot.com)**
> >
> > I know it hurts. Try not to think.
> 
> [http://sinfoniaferida.blogspot.com](http://sinfoniaferida.blogspot.com)

---

<div class="post-metadata">

**Author:** ![Guest5](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@Guest5](https://rubytalk.org/u/Guest5)\
**Post date:** [29 June 2007 21:50 UTC](https://rubytalk.org/t/active-record-not-found/38758/3 "2007-06-29T21:50:17Z")

</div>

Gray Bowman wrote:

> require 'rubygems'  
> gem 'activerecord'

[snip]

> require 'active\_record'  
> and it seems to work, until:

activerecord != active\_record 😉

To require gems you need also to require rubygems:

&nbsp;&nbsp;require 'rubygems'  
&nbsp;&nbsp;require 'active\_record'

Regards  
Jan

---

<div class="post-metadata">

**Author:** ![Gray\_Bowman](https://avatars.discourse-cdn.com/v4/letter/g/74df32/32.png) [@Gray\_Bowman](https://rubytalk.org/u/Gray_Bowman)\
**Post date:** [29 June 2007 21:02 UTC](https://rubytalk.org/t/active-record-not-found/38758/4 "2007-06-29T21:02:26Z")

</div>

> What happens if you replace "gem 'activerecord'" with "require  
> 'activerecord'"?

Upon changing I receive this error:  
C:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem\_original\_require': no such file to load -- activerecord (LoadError)  
&nbsp;&nbsp;from C:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`require'  
&nbsp;&nbsp;from app/gatherer.rb:3

Which to my eyes appears that activerecord may not be installed.  
HOWEVER I tried this:

require 'active\_record'

and it seems to work, until:

C:\InstantRails\ruby\lib\ruby\gems\1.8\gems\activesupport-1.4.2\lib/active\_support/dependencies.rb:376:in  
`new_constants_in': undefined method `empty?' for nil:NilClass  
(NoMethodError)  
&nbsp;&nbsp;from  
C:\InstantRails\ruby\lib\ruby\gems\1.8\gems\activesupport-1.4.2\lib/active\_support/dependencies.rb:495:in  
`require'  
&nbsp;&nbsp;from  
C:\InstantRails\ruby\lib\ruby\gems\1.8\gems\activesupport-1.4.2\lib/active\_support.rb:34  
&nbsp;&nbsp;from  
C:\InstantRails\ruby\lib\ruby\gems\1.8\gems\activerecord-1.15.3\lib/active\_record.rb:30:in  
`require'  
&nbsp;&nbsp;from  
C:\InstantRails\ruby\lib\ruby\gems\1.8\gems\activerecord-1.15.3\lib/active\_record.rb:30  
&nbsp;&nbsp;from app/gatherer.rb:2:in `require'  
&nbsp;&nbsp;from app/gatherer.rb:2

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Gray\_Bowman](https://avatars.discourse-cdn.com/v4/letter/g/74df32/32.png) [@Gray\_Bowman](https://rubytalk.org/u/Gray_Bowman)\
**Post date:** [29 June 2007 22:16 UTC](https://rubytalk.org/t/active-record-not-found/38758/5 "2007-06-29T22:16:19Z")

</div>

Jan Friedrich wrote:

> activerecord != active\_record 😉
> 
> To require gems you need also to require rubygems:
> 
> &nbsp;&nbsp;require 'rubygems'  
> &nbsp;&nbsp;require 'active\_record'

So I guess I'm really confused then. This is my final code:

require 'net/http'  
require 'active\_record'

ActiveRecord::Base.establish\_connection(  
&nbsp;&nbsp;:adapter =\> 'mysql',  
&nbsp;&nbsp;:host =\> 'localhost',  
&nbsp;&nbsp;:username =\> 'root',  
&nbsp;&nbsp;:password =\> '',  
&nbsp;&nbsp;:database =\> 'app\_development')

class Thing \< ActiveRecord::Base  
end

This works in IRB, and on the command line. I'm happy now, but still  
wondering...

I didn't have to "require 'rubygems'" for this to work, why? Isn't  
ActiveRecord a gem? And if so, shouldn't I have to use "gem  
'active\_record'" instead?

Also, if there wasn't an error on the \_old\_ line "require  
'activerecord'" then ruby found something by that name ... what was it?

Finally, and this is where you can really help me: Where can I find  
this info in the documentation. I've looked in the core reference, the  
standard lib reference, and read the whole ActiveRecord section and  
found nothing telling me how the \_right\_ way to include this was, what I  
found was different people doing it different ways, none of which worked  
for me.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Michael\_Hollins](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@Michael\_Hollins](https://rubytalk.org/u/Michael_Hollins)\
**Post date:** [30 June 2007 02:30 UTC](https://rubytalk.org/t/active-record-not-found/38758/6 "2007-06-30T02:30:07Z")

</div>

Gray Bowman wrote:

> Jan Friedrich wrote:
> 
> > activerecord != active\_record 😉
> > 
> > To require gems you need also to require rubygems:
> > 
> > &nbsp;&nbsp;require 'rubygems'  
> > &nbsp;&nbsp;require 'active\_record'
> 
> So I guess I'm really confused then. This is my final code:
> 
> require 'net/http'  
> require 'active\_record'
> 
> ActiveRecord::Base.establish\_connection(  
> &nbsp;&nbsp;:adapter =\> 'mysql',  
> &nbsp;&nbsp;:host =\> 'localhost',  
> &nbsp;&nbsp;:username =\> 'root',  
> &nbsp;&nbsp;:password =\> '',  
> &nbsp;&nbsp;:database =\> 'app\_development')
> 
> class Thing \< ActiveRecord::Base  
> end
> 
> This works in IRB, and on the command line. I'm happy now, but still wondering...
> 
> I didn't have to "require 'rubygems'" for this to work, why? Isn't ActiveRecord a gem? And if so, shouldn't I have to use "gem 'active\_record'" instead?

Do you happen to have the RUBYOPT environment variable set as follows?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RUBYOPT=-rubygems
