Felix
Felix

Reputation: 699

Manually connect to PostgreSQL with Ruby

Connecting to postgres with rails was no big deal. rails -d postgresql app_name, setup the database.yml and voila. I cannot, however, use postgres with just a little test script

I've tried installing the gems postgres, dbi & dbd-pg, pg, and ruby-pg, but with pg/ruby-pg and postgres it fails at the require for require 'postgres' or require 'pg'. With require 'dbi' I get past the require, but it can't load the driver....so how is rails doing it with the same set of packages? In fact I removed all the afore mentioned and found I only needed the 'pg' gem for everything to work fine with rails. Any advice?

Upvotes: 2

Views: 1701

Answers (1)

Brian Campbell
Brian Campbell

Reputation: 333046

Are you remembering to add a require 'rubygems' to your source, or invoke ruby with a -rubygems argument, or add RUBYOPT=rubygems to your environment? You need to do one of those to actually load the gem machinery that allows require to find your gems.

Upvotes: 3

Related Questions