Skip to content

Instantly share code, notes, and snippets.

@agoodman
Created January 15, 2013 04:15
Show Gist options
  • Save agoodman/4535983 to your computer and use it in GitHub Desktop.
Save agoodman/4535983 to your computer and use it in GitHub Desktop.
bad ssl practice in controller logic
class BadSslController < ApplicationController
before_filter :enforce_https
def enforce_https
if use_ssl?
if request.protocol != 'https://'
redirect_to url_for(controller: controller_name, action: action_name, protocol: 'https') and return
end
else
if request.protocol != 'http://'
redirect_to url_for(controller: controller_name, action: action_name, protocol: 'http') and return
end
end
end
def use_ssl?
if controller_name=='orders'
if action_name=='index' || action_name=='show'
true
else
false
end
elsif controller_name=='troops'
if action_name=='index' || action_name=='show'
true
else
false
end
elsif controller_name=='generals'
true
end
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment