enblpq
Last Updated: February 25, 2016
·
2.248K
· sshingler
1cb5d53d5bbf3e3afa7960ef55c240e4

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 }
Say Thanks
Respond