Active Record not found

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.

On 6/29/07, Gray B. [email protected] 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’”?

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:inrequire’
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 methodempty?’ 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:inrequire’
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

Gray B. wrote:

require ‘rubygems’
gem ‘activerecord’
[snip]
require ‘active_record’
and it seems to work, until:

activerecord != active_record :wink:

To require gems you need also to require rubygems:

require ‘rubygems’
require ‘active_record’

Regards
Jan

Jan F. wrote:

activerecord != active_record :wink:

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.

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