Skip to content

HHRy/client_database_switching

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

Client Database Switching

How to automatically switch client databases using Rails.

This is the code that accompanies my Tutorial on the matter and is based on the orignal solution Mark Somerville wrote at PCCL in 2007.

Usage:

  1. Install as a plugin
  2. Create Directory /config/databases in your Rails app root
  3. Create /config/databases/localhost.yml in your Rails app root
  4. With contents:
	<%= { "database_details" => ActiveRecord::Base.configurations["development"] }.to_yaml %>

Then, add in your Application Controller:

	prepend_before_filter :choose_database_from_host

YAML File Format

Databases config files must take the following form:

	# Contents of ryanstenhouse.eu.yml
	database_details:
	  adapter: mysql
	  database: client_db_name
	  username: root
	  password:

Releases

No releases published

Packages

No packages published

Languages