Can't get ActiveRecord to work with Ruby and Postgres

Discussion in 'Ruby' started by Steve Litt, Aug 25, 2006.

  1. Steve Litt

    Steve Litt Guest

    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'")
     
    Steve Litt, Aug 25, 2006
    #1
    1. Advertising

  2. Steve Litt

    Steve Litt Guest

    On Friday 25 August 2006 02:45 pm, Jake Cutter wrote:
    > On 8/25/06, Steve Litt <> wrote:
    > > ActiveRecord::Base.establish_connection(
    > > # :adapter => "mysql",
    > >
    > > :adapter => "pg", # adapter not found error, investigate
    > > :database => "test",
    > > :user => "myid"
    > >
    > > )

    >
    > 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
     
    Steve Litt, Aug 25, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Espada
    Replies:
    0
    Views:
    105
    David Espada
    May 18, 2005
  2. _blackdog

    activerecord, postgres and views?

    _blackdog, Jan 11, 2006, in forum: Ruby
    Replies:
    1
    Views:
    115
    _blackdog
    Jan 11, 2006
  3. Nick Black
    Replies:
    1
    Views:
    165
    Kashia Buch
    Nov 16, 2006
  4. Chris Long

    ruby-postgres for Ruby 1.9

    Chris Long, Feb 28, 2007, in forum: Ruby
    Replies:
    1
    Views:
    111
    Jeff Davis
    Feb 28, 2007
  5. Dillip Kumar
    Replies:
    5
    Views:
    107
    Kevin Williams
    Nov 24, 2007
Loading...

Share This Page