Skip to content

Instantly share code, notes, and snippets.

@Bill
Created May 15, 2009 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bill/112265 to your computer and use it in GitHub Desktop.
Save Bill/112265 to your computer and use it in GitHub Desktop.
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