Guest User

Untitled

a guest
Mar 15th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. # Filters added to this controller apply to all controllers in the application.
  2. # Likewise, all the methods added will be available for all controllers.
  3.  
  4. class ApplicationController < ActionController::Base
  5. before_filter :switchdb
  6.  
  7. helper :all # include all helpers, all the time
  8.  
  9. # See ActionController::RequestForgeryProtection for details
  10. # Uncomment the :secret if you're not using the cookie session store
  11. protect_from_forgery # :secret => 'e8c126ac89e3390411ef888b2723c200'
  12.  
  13. protected
  14. # JS - I'm using the same files for two production locations, tiwictest.coolhuntr.com and tiwic.coolhuntr.com
  15. # JS - Switchdb will switch the db when the domain is tiwictest.coolhuntr.com
  16. # JS - This saves me the trouble of editing the database.yml manually everytime I need to ftp to
  17. # JS - both the tiwictest.coolhuntr.com and tiwic.coolhuntr.com subdomains.
  18. # JS - To access the request variable, I had to make this method protected and call it in a before filter.
  19. def switchdb
  20. if request.subdomains.first =~ /tiwictest/
  21. ActiveRecord::Base.establish_connection(
  22. :adapter => "mysql",
  23. :host => "obscured",
  24. :username => "obscured",
  25. :password => "obscured",
  26. :database => "obscured",
  27. :encoding => "utf8"
  28. )
  29.  
  30. # JS - require http auth for tiwictest so I can test in secret
  31. authenticate_testsite
  32.  
  33. # JSJust a testing variable I'm using in the view for now
  34. @tiwictest = "yes"
  35.  
  36. else
  37. @tiwictest = "no"
  38. end
  39. end
  40.  
  41. def authenticate_testsite
  42. authenticate_or_request_with_http_basic("Who goes thar?") do |username, password|
  43. username == 'obscured' && password == 'obscured'
  44. end
  45. end
  46.  
  47.  
  48. end
Add Comment
Please, Sign In to add comment