Manual active record db connection in ruby using mysql adapter

Here is the code to make manual connection with database
 
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "root",
:password => "abcd",
:database => "funonrails"
)

Load database configurations from yml file

 
dbconfig = YAML::load(File.open('database.yml'))
ActiveRecord::Base.establish_connection( dbconfig )

2 thoughts on “Manual active record db connection in ruby using mysql adapter

  1. This is because YAML libray is not installed or not in path.Add library to your code before that ensure it exists.require "yaml"dbconfig = YAML::load(File.open('database.yml'))ActiveRecord::Base.establish_connection( dbconfig )

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.