Last Updated: February 25, 2016
·
2.507K
· sshingler

Connect to a database using ActiveRecord outside of Rails

require 'active_record'

ActiveRecord::Base.establish_connection(
  :adapter =>  "mysql2",
  :encoding =>  "utf8",
  :reconnect =>  true,
  :pool =>  5,
  :username =>  'root',
  :host =>  "localhost",
  :database =>  "my_database")

Dir.glob('./app/models/*').each { |r| require r }