Skip to content

Instantly share code, notes, and snippets.

@jmccartie
Created June 16, 2011 20:30
Show Gist options
  • Save jmccartie/1030191 to your computer and use it in GitHub Desktop.
Save jmccartie/1030191 to your computer and use it in GitHub Desktop.
Force / unforce SSL based on given hash of pages you with to protect
def force_ssl
pages = {"giving" => ["login", "give"]}
pages.each do |controller, actions|
if params[:controller] == controller && actions.include?(params[:action])
if !request.ssl? && !Rails.env.development?
redirect_to :protocol => 'https://', :status => :moved_permanently
end
elsif request.ssl?
redirect_to :protocol => 'http://', :status => :moved_permanently
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment