Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Filters added to this controller apply to all controllers in the application.
- # Likewise, all the methods added will be available for all controllers.
- class ApplicationController < ActionController::Base
- before_filter :switchdb
- helper :all # include all helpers, all the time
- # See ActionController::RequestForgeryProtection for details
- # Uncomment the :secret if you're not using the cookie session store
- protect_from_forgery # :secret => 'e8c126ac89e3390411ef888b2723c200'
- protected
- # JS - I'm using the same files for two production locations, tiwictest.coolhuntr.com and tiwic.coolhuntr.com
- # JS - Switchdb will switch the db when the domain is tiwictest.coolhuntr.com
- # JS - This saves me the trouble of editing the database.yml manually everytime I need to ftp to
- # JS - both the tiwictest.coolhuntr.com and tiwic.coolhuntr.com subdomains.
- # JS - To access the request variable, I had to make this method protected and call it in a before filter.
- def switchdb
- if request.subdomains.first =~ /tiwictest/
- ActiveRecord::Base.establish_connection(
- :adapter => "mysql",
- :host => "obscured",
- :username => "obscured",
- :password => "obscured",
- :database => "obscured",
- :encoding => "utf8"
- )
- # JS - require http auth for tiwictest so I can test in secret
- authenticate_testsite
- # JSJust a testing variable I'm using in the view for now
- @tiwictest = "yes"
- else
- @tiwictest = "no"
- end
- end
- def authenticate_testsite
- authenticate_or_request_with_http_basic("Who goes thar?") do |username, password|
- username == 'obscured' && password == 'obscured'
- end
- end
- end
Add Comment
Please, Sign In to add comment