Getting Rails URL helpers to automatically output https urls

后端 未结 7 2052
再見小時候
再見小時候 2020-12-25 12:02

I am developing a site that mixes http and https a lot - whats the best/easiest way to make the links use the right protocol for the route - can it be specified in the route

相关标签:
7条回答
  • 2020-12-25 12:36

    Haven't tried but add this in your ApplicationController:

    def default_url_options(options={})
     { :secure => true }
    end 
    
    0 讨论(0)
  • 2020-12-25 12:39

    For Rails 3.2 I used a combination of @apneadiving's answer. Adding the below code to my ApplicationController

    def default_url_options(options={})
      options.merge{ :protocol => "https" }
    end
    
    0 讨论(0)
  • 2020-12-25 12:40
    def default_url_options(options={})
     { :protocol => "https" }
    end
    
    0 讨论(0)
  • 2020-12-25 12:43

    Use test_url(:protocol => 'https') for https urls.

    0 讨论(0)
  • 2020-12-25 12:47

    You can use a plugin called ss_requirement, it will provide you with methods like ssl_required ssl_allowed

    You can simply add this in your controller to enable ot disable https on any action

    ssl_allowed :login, :update_profile
    

    https://github.com/rails/ssl_requirement

    0 讨论(0)
  • 2020-12-25 12:54

    Rails 3 SSL routing redirects from https to http answers this question pretty well. In short, there's not a great way to do it. I submitted the following Rails bug: https://github.com/rails/rails/issues/3571

    0 讨论(0)
提交回复
热议问题