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 comment

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