Guest User

Untitled

a guest
May 3rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. class ApplicationController < ActionController::Base
  2. helper :all # include all helpers, all the time
  3. before_filter :use_alternate_db
  4. protect_from_forgery :secret => 'abc'
  5.  
  6. private
  7. def use_alternate_db
  8. if request.host == 'localhost'
  9. # ActiveRecord::Base.establish_connection :development
  10. regular_db
  11. elsif request.host == 'othername'
  12. alternate_db
  13. end
  14.  
  15. end
  16.  
  17. def regular_db
  18. ActiveRecord::Base.establish_connection(
  19. :adapter => 'mysql',
  20. :host => 'localhost',
  21. :username => 'root',
  22. :password => nil,
  23. :database => 'db1'
  24. )
  25.  
  26. end
  27.  
  28. def alternate_db
  29. ActiveRecord::Base.establish_connection(
  30. :adapter => 'mysql',
  31. :host => 'otherdbhost.com',
  32. :username => 'user',
  33. :password => 'password',
  34. :database => 'db2'
  35. )
  36.  
  37. end
  38. end
Add Comment
Please, Sign In to add comment