Created
May 19, 2017 12:27
-
-
Save terry90/e211a7ba9c2591b0a6a8cd36e793188a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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