Created
May 15, 2009 15:53
-
-
Save Bill/112265 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
before_filter :set_database_for_cluster_stuff | |
# SourceSpecific and subclasses (Content, Cluster) take up a lot of space so we want them in | |
# their own per-Domain databases. This hook injects the appropriate database connection based | |
# on the Domain gleaned from the request so subsequent access (during this request) | |
# will go to the appropriate database. | |
def set_database_for_cluster_stuff | |
config = ActiveRecord::Base.configurations[RAILS_ENV] | |
# Get the database name from the Domain | |
# everything else (username, password) is the same as the default environment | |
connection_parameters = config.merge({'database' => current_domain.cluster_database_name}) | |
# Content and Cluster are subclasses of SourceSpecific so they'll ge their connections from it | |
SourceSpecific.class_eval do | |
establish_connection( connection_parameters ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment