Created
November 4, 2009 03:36
-
-
Save edavis10/225753 to your computer and use it in GitHub Desktop.
Rails configuration for using two different databases.
This file contains hidden or 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
# Abstraction to connect to the second database | |
module SecondDatabase | |
def self.included(base) | |
base.class_eval do | |
establish_connection :source_redmine | |
end | |
end | |
end |
This file contains hidden or 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 SourceUser < ActiveRecord::Base | |
include SecondDatabase | |
set_table_name :users | |
end |
This file contains hidden or 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
# Override the actual second database connection code in order to test | |
# against a known database | |
module SecondDatabase | |
def self.included(base) | |
base.class_eval do | |
establish_connection("adapter" => 'sqlite3', "database" => File.expand_path(File.dirname(__FILE__) + '/test_database.sqlite3')) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment