Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 1.03 KB

README.md

File metadata and controls

43 lines (32 loc) · 1.03 KB

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: