I’d like to redirect all site traffic from all controllers to https while in production. Probably using something like the following:
before_filter :redirect_to_https
With the following in the controller:
def redirect_to_https
redirect_to :protocol => "https://" unless (request.ssl? || local_request? || Rails.env.development? || Rails.env.staging? ) # probably don't need redundant development with `local_request` present
end
What is the most effective way to apply this to all controllers vs having to repeat this in each controller?
Use
config.force_ssl = truein your environments/production.rb config file.If you want a before_filter to apply to all controllers, they all inherit from ApplicationController so put it in there.