Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ApplicationController < ActionController::Base
- protect_from_forgery
- before_filter :override_db
- def override_db
- begin
- if Rails.env.production?
- @application_name = request.env['HTTP_HOST'][/^[\w]+/]
- else
- @application_name = ""
- return
- end
- ActiveRecord::Base.connection_pool.clear_reloadable_connections!
- ActiveRecord::Base.establish_connection(
- :adapter => "mysql2",
- :host => "",
- :username => "",
- :password => "",
- :database => "myapp_#{@application_name}"
- )
- rescue Exception => e
- # Database can't be found/connected to
- end
- end
Add Comment
Please, Sign In to add comment