awkward silence |

Archive for November 23rd, 2005

Nov/05

23

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.

No tags

Theme Design by devolux.nh2.me