Active Record not found

G

Gray Bowman

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

Bira

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'"?
 
G

Gray Bowman

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
 
J

Jan Friedrich

Gray said:
gem 'activerecord'
activerecord != active_record ;)

Use

require 'rubygems'
require 'active_record'

or alternative

require 'rubygems'
require 'active_record'


Regards
Jan
 
J

Jan Friedrich

Gray said:
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
 
G

Gray Bowman

Jan said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top