Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ApplicationController < ActionController::Base
- helper :all # include all helpers, all the time
- before_filter :use_alternate_db
- protect_from_forgery :secret => 'abc'
- private
- def use_alternate_db
- if request.host == 'localhost'
- # ActiveRecord::Base.establish_connection :development
- regular_db
- elsif request.host == 'othername'
- alternate_db
- end
- end
- def regular_db
- ActiveRecord::Base.establish_connection(
- :adapter => 'mysql',
- :host => 'localhost',
- :username => 'root',
- :password => nil,
- :database => 'db1'
- )
- end
- def alternate_db
- ActiveRecord::Base.establish_connection(
- :adapter => 'mysql',
- :host => 'otherdbhost.com',
- :username => 'user',
- :password => 'password',
- :database => 'db2'
- )
- end
- end
Add Comment
Please, Sign In to add comment