Can't get ActiveRecord to work with Ruby and Postgres

S

Steve Litt

Hi all,

I'm experimenting with ActiveRecord with Ruby -- no Rails. I installed both
the Mysql and Postgres (the C one, not the fully Ruby one) database dependent
drivers. I can use them to manipulate their databases, respectively. I
installed DBI, and can get it to manipulate both the MySQL and the Postgres
database, and except for a couple things, do it in a database independent
way.

I installed ActiveRecord (via an old Rails install), and can get it to
interact with the MySQL database. However, when I try to get it to interact
with the Postgres database, I get the following error:

[slitt@mydesk ~]$ ./test2.rb
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:79:in
`establish_connection': database configuration specifies nonexistent pg
adapter (ActiveRecord::AdapterNotFound)
from ./test2.rb:5
[slitt@mydesk ~]$

I'll leave my code at the bottom of this email. When I comment out
the :adapter =>"pg" statement, it works perfectly with MySQL. But when I
instead comment out the :adapter =>"mysql" statement, it errors out as
explained earlier.

What steps should I take to identify the cause of this problem?

Thanks

SteveT

#!/usr/bin/ruby
require 'rubygems'
require_gem 'activerecord'

ActiveRecord::Base.establish_connection(
# :adapter => "mysql",
:adapter => "pg", # adapter not found error, investigate
:database => "test",
:user => "myid"
)

class Rock < ActiveRecord::Base
end

newrow = Rock.new
newrow.rockname = "Bassalt"
newrow.save

puts Rock.find:)first).rockname
puts "Now let's see them all!"
whatever = Rock.find:)all)
whatever.each do |row|
print row.id, " ", row.rockname, "\n"
end

Rock.delete_all("rockname = 'Bassalt'")
 
S

Steve Litt

Shouldn't the above be

:adapter=>"postgresql"

Yep! That fixed it. I still have some sort of permission problem, but I can
fix that.

Thanks Jake.

Steve

Steve Litt
Author:
* Universal Troubleshooting Process courseware
* Troubleshooting Techniques of the Successful Technologist
* Manager's Guide to Technical Troubleshooting
* Twenty Eight Tales of Troubleshooting
* Rapid Learning: Secret Weapon of the Successful Technologist

http://www.troubleshooters.com/bookstore
http://www.troubleshooters.com/utp/tcourses.htm
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top