Created
October 8, 2014 23:33
-
-
Save shannonwells/a068697f15bc4b4062f9 to your computer and use it in GitHub Desktop.
How to set up using a different database in rails from the default
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
class MyclassBase < ActiveRecord::Base | |
self.abstract_class = true | |
CONFIG_PATH = File.join(Rails.root, 'config', 'database_myclass.yml') unless defined? CONFIG_PATH | |
# So you can use environment variables in your YML file. | |
erb = ERB.new(File.read(CONFIG_PATH)).result | |
config = ActiveSupport::HashWithIndifferentAccess.new(YAML.load(erb))[Rails.env] | |
raise ConfigurationNotFound.new("Configuration not found for config_path: '#{CONFIG_PATH}'") unless config | |
establish_connection( | |
adapter: config[:adapter], | |
username: config[:username], | |
password: config[:password], | |
dataserver: config[:dataserver], | |
database: config[:database] | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment