NEWS:

Uncategorized 23 Nov 2005 02:57 pm

Quick DB Connection Test

If you’re having trouble connecting this snippet may help. This is handy as it runs in isolation from the rest of your Rails application which can be very useful in debugging.

Change the name of the class to be one of your table names (singular).


require ‘rubygems’
require ‘active_record’

ActiveRecord::Base.establish_connection(
:adapter => “mysql”,
:host => “db.xyz.com”,
:username => “user”,
:password => “pass”,
:database => “dbname”)

class Person < ActiveRecord::Base

def initialize
puts “initialize”
super
end

end

t = Person.new

If you connect you won’t see any errors. Otherwise you should get an error that has some useful info.

Comments are closed.