Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.