Skip to content

Instantly share code, notes, and snippets.

@terry90
Created May 19, 2017 12:27
Show Gist options
  • Save terry90/e211a7ba9c2591b0a6a8cd36e793188a to your computer and use it in GitHub Desktop.
Save terry90/e211a7ba9c2591b0a6a8cd36e793188a to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'yaml'
require 'erb'
require 'active_record'
config_dir = File.expand_path('../', __FILE__)
config_content = File.read(File.join(config_dir, 'database.yml'))
db_conf = YAML.safe_load(ERB.new(config_content).result)
env = ENV['RACK_ENV'] || 'development'
ActiveRecord::Base.establish_connection db_conf[env]
logger = if %w[development test].include? env
Logger.new(File.open('log/db.log', 'a'))
else
Logger.new(STDOUT)
end
ActiveRecord::Base.logger = logger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment