Force SSL for specific routes in Rails 3.1

后端 未结 3 1026
[愿得一人]
[愿得一人] 2021-02-20 04:32

I need to force SSL on all routes in my application except for landing#index.

In config/application.rb, I have:



        
3条回答
  •  借酒劲吻你
    2021-02-20 05:02

    Rails 4 with ActiveAdmin 1.0b, I modified config/initializers/active_admin.rb:

    config.before_filter :force_ssl_redirect, if: :https_enabled?
    

    force_ssl_redirect is defined in actionpack/lib/action_controller/metal/force_ssl.rb and is what Rails' force_ssl class method calls.

    https_enabled? defined in my application_controller.rb:

    def https_enabled?
      ENV['HTTPS_ENABLED'] == 'true'
    end
    

提交回复
热议问题