Skip to content

Instantly share code, notes, and snippets.

@ehoch
Last active December 11, 2015 17:49
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehoch/4637443 to your computer and use it in GitHub Desktop.
Save ehoch/4637443 to your computer and use it in GitHub Desktop.
Full Site SSL in Spree
Spree::BaseController.class_eval do
protected
def ssl_required?
ssl_supported? and request.format != 'application/xml'
end
def ensure_proper_protocol
return true if ssl_allowed?
if ssl_required? && !request.ssl? && ssl_supported?
redirect_to "https://" + request.host + request.fullpath, :status => 301
flash.keep
elsif request.ssl? && !ssl_required?
redirect_to "http://" + request.host + request.fullpath
flash.keep
end
end
end

Curious how Alarm Grid went full site-wide SSL using Spree? Just create the one decorator below and you're good to go!

Note: This gist will not redirect .xml files so that our feeds do not error out on iPhones which do not support RSS feeds in https.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment