# Active Record not found

**URL:** <https://www.ruby-forum.com/t/active-record-not-found/108194>\
**Category:** Ruby\
**Created:** [June 29, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/active-record-not-found/108194 "2007-06-29T22:34:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lu5t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lu5t](https://www.ruby-forum.com/u/lu5t)\
**Post date:** [June 29, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/active-record-not-found/108194/1 "2007-06-29T22: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(  
:adapter =\> ‘mysql’,  
:host =\> ‘localhost’,  
:username =\> ‘root’,  
:password =\> ‘’,  
: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.

---

<div class="post-metadata">

**Author:** ![lu5t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lu5t](https://www.ruby-forum.com/u/lu5t)\
**Post date:** [June 29, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/active-record-not-found/108194/2 "2007-06-29T22:40:22Z")

</div>

On 6/29/07, Gray B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

What happens if you replace “gem ‘activerecord’” with “require  
‘activerecord’”?

---

<div class="post-metadata">

**Author:** ![lu5t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lu5t](https://www.ruby-forum.com/u/lu5t)\
**Post date:** [June 29, 2007, 11:02pm UTC](https://www.ruby-forum.com/t/active-record-not-found/108194/3 "2007-06-29T23: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) from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`require’  
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)  
from  
C:\InstantRails\ruby\lib\ruby\gems\1.8\gems\activesupport-1.4.2\lib/active\_support/dependencies.rb:495:in  
`require' from C:\InstantRails\ruby\lib\ruby\gems\1.8\gems\activesupport-1.4.2\lib/active_support.rb:34 from C:\InstantRails\ruby\lib\ruby\gems\1.8\gems\activerecord-1.15.3\lib/active_record.rb:30:in`require’  
from  
C:\InstantRails\ruby\lib\ruby\gems\1.8\gems\activerecord-1.15.3\lib/active\_record.rb:30  
from app/gatherer.rb:2:in `require’  
from app/gatherer.rb:2

---

<div class="post-metadata">

**Author:** ![lu5t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lu5t](https://www.ruby-forum.com/u/lu5t)\
**Post date:** [June 29, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/active-record-not-found/108194/4 "2007-06-29T23:51:29Z")

</div>

Gray B. 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:

require ‘rubygems’  
require ‘active\_record’

Regards  
Jan

---

<div class="post-metadata">

**Author:** ![lu5t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lu5t](https://www.ruby-forum.com/u/lu5t)\
**Post date:** [June 30, 2007, 12:16am UTC](https://www.ruby-forum.com/t/active-record-not-found/108194/5 "2007-06-30T00:16:19Z")

</div>

Jan F. wrote:

> activerecord != active\_record 😉
> 
> To require gems you need also to require rubygems:
> 
> require ‘rubygems’  
> 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(  
:adapter =\> ‘mysql’,  
:host =\> ‘localhost’,  
:username =\> ‘root’,  
:password =\> ‘’,  
: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.

---

<div class="post-metadata">

**Author:** ![lu5t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lu5t](https://www.ruby-forum.com/u/lu5t)\
**Post date:** [June 30, 2007, 4:30am UTC](https://www.ruby-forum.com/t/active-record-not-found/108194/6 "2007-06-30T04:30:46Z")

</div>

Gray B. wrote:

> 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?

```
 RUBYOPT=-rubygems
```
