ActiveRecord with Ruby alone
30 Oct 2012Active Record is the main tool that Rails developers use to communicate with and underlying database. Active Record does some wonderful things for a web developer looking for abstractions in database setup, SQL connections and queries. We can get a cool command line Ruby application or utility script for our daily tasks using Active Record going in about 5 minutes!
First of all, get the activerecord gem using
gem install activerecord
At the top of Ruby program we need to require the Active Record gem previously installed. Interacting with your database will be a pleasure now!
require 'activerecord'
Establishing a connection to database
ActiveRecord::Base.establish_connection {
adapter: "mysql",
host: "localhost",
username: "root",
password: "password",
database: "dbname"
}