link_to with :protocol isn't working

后端 未结 2 1141
面向向阳花
面向向阳花 2021-02-13 07:12

I want to have a link use SSL. I\'m using this code:

<%= link_to \"Buy now!\", line_items_path(:thing_id => @thing), :method => :post, :protocol => \         


        
相关标签:
2条回答
  • 2021-02-13 08:02

    You must put the :protocol option inside the path helper:

    <%= link_to "Buy now!", line_items_url(:thing_id => @thing, :protocol => "https"), :method => :post %>
    
    0 讨论(0)
  • 2021-02-13 08:08

    If you are using bartt-ssl_requirement rubygem in your app, you can use the ssl-url-helper to explicitly mention http or https protocol.

    Advantages:

    1. If you've disabled SSL check (in development environment), by following way: SslRequirement.disable_ssl_check = true, then passing :secure => true won't explicitly add https links to your view. This is not the case if you specify :protocol => 'https' and disable SSL check.

    2. Also, its not necessary to change line_items_path to line_items_url at each place.

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