Here’s a simple enhancement to my previous entry regarding using ActiveRecord – we’re using YAML to move the database connection information outside of the Ruby file. The “connect” method is changed as follows:
require 'active_record' require 'yaml' class ActiveRecordTest # Create a connection. def connect #use YAML to define the connection information. dbconfig = YAML::load(File.open('database.yml')) ActiveRecord::Base.establish_connection(dbconfig) end ...
and the YAML file looks like this:
adapter: postgresql database: Test username: [username] password: [password] host: localhost
Again replacing [username] and [password] with the actual username and password that has the desired permissions on your database.