Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 25 lines (22 sloc) 0.556 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
module SimpleSSLRequirement
  def self.included(base)
    base.extend(ClassMethods)
    base.class_eval do
      private

      def require_ssl
        if !request.ssl?
          redirect_to "https://#{request.host}#{request.fullpath}"
          flash.keep
        end
      end
    end
  end

  module ClassMethods
    def ssl_required(options={})
      options.reverse_merge!(:environments => %w(production staging test))

      if options.delete(:environments).include?(Rails.env)
        before_filter :require_ssl, options
      end
    end
  end
end
Something went wrong with that request. Please try again.