SSL with Ruby on Rails

前端 未结 4 852
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 22:29

What do I need to do to get traffic to my ruby on rails app to use https? I have a certificate installed and if I manually type in \"https://\" in the address bar when accessin

4条回答
  •  佛祖请我去吃肉
    2021-01-31 22:34

    Check out the ssl_requirement gem.

    It lets you specify in your controllers which actions should be served over https and which actions can be served over https. It will then take care of redirecting from http to https and vice-versa.

    From the documentation:

    class ApplicationController < ActiveRecord::Base
      include SslRequirement
    end
    
    class AccountController < ApplicationController
      ssl_required :signup, :payment
      ssl_allowed :index
    
      def signup
        # Non-SSL access will be redirected to SSL
      end
    
      def payment
        # Non-SSL access will be redirected to SSL
      end
    
      def index
        # This action will work either with or without SSL
      end
    
      def other
        # SSL access will be redirected to non-SSL
      end
    end
    

提交回复
热议问题