Skip to content

Instantly share code, notes, and snippets.

@edavis10
Created November 4, 2009 03:36
Show Gist options
  • Save edavis10/225753 to your computer and use it in GitHub Desktop.
Save edavis10/225753 to your computer and use it in GitHub Desktop.
Rails configuration for using two different databases.
# Abstraction to connect to the second database
module SecondDatabase
def self.included(base)
base.class_eval do
establish_connection :source_redmine
end
end
end
class SourceUser < ActiveRecord::Base
include SecondDatabase
set_table_name :users
end
# 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