Guest User

Untitled

a guest
Sep 24th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. class ApplicationController < ActionController::Base
  2.  
  3. protect_from_forgery
  4.  
  5. before_filter :override_db
  6.  
  7. def override_db
  8. begin
  9. if Rails.env.production?
  10. @application_name = request.env['HTTP_HOST'][/^[\w]+/]
  11. else
  12. @application_name = ""
  13. return
  14. end
  15.  
  16. ActiveRecord::Base.connection_pool.clear_reloadable_connections!
  17.  
  18. ActiveRecord::Base.establish_connection(
  19. :adapter => "mysql2",
  20. :host => "",
  21. :username => "",
  22. :password => "",
  23. :database => "myapp_#{@application_name}"
  24. )
  25. rescue Exception => e
  26. # Database can't be found/connected to
  27. end
  28. end
Add Comment
Please, Sign In to add comment