link_to with:协议无效

Tim*_*van 14 ruby-on-rails

我想要一个链接使用SSL.我正在使用此代码:

<%= link_to "Buy now!", line_items_path(:thing_id => @thing), :method => :post, :protocol => "https", :only_path => false %>
Run Code Online (Sandbox Code Playgroud)

出于某种原因,正在生成链接http://而不是https://.

我正在使用Rails 3.0.3.

Rya*_*igg 24

您必须将:protocol选项放在路径助手中:

<%= link_to "Buy now!", line_items_url(:thing_id => @thing, :protocol => "https"), :method => :post %>
Run Code Online (Sandbox Code Playgroud)

  • 仅供参考,这里的真正诀窍是将line_items_path更改为line_items_url,因为路径助手不支持:protocol (10认同)
  • 如果我没弄错的话,:only_path => false是必要的.只有在指定host时才能省略它. (3认同)