Ruby on rails 链接到:协议isn';行不通
我想有一个使用SSL的链接。我正在使用以下代码:Ruby on rails 链接到:协议isn';行不通,ruby-on-rails,Ruby On Rails,我想有一个使用SSL的链接。我正在使用以下代码: <%= link_to "Buy now!", line_items_path(:thing_id => @thing), :method => :post, :protocol => "https", :only_path => false %> @thing],:method=>:post,:protocol=>“https”,:only_path=>false%> 出于某种原因,正在使用http://
<%= link_to "Buy now!", line_items_path(:thing_id => @thing), :method => :post, :protocol => "https", :only_path => false %>
@thing],:method=>:post,:protocol=>“https”,:only_path=>false%>
出于某种原因,正在使用http://
而不是https://
生成链接
我使用的是Rails 3.0.3。您必须将:protocol选项放在路径帮助器中:
<%= link_to "Buy now!", line_items_url(:thing_id => @thing, :protocol => "https"), :method => :post %>
@thing,:protocol=>“https”),:method=>:post%>
如果您在应用程序中使用rubygem,您可以使用来明确提及http或https协议
优点:
SslRequirement.disable\u SSL\u check=true
,然后传递:secure=>true
不会显式地将https链接添加到您的视图中。如果指定:协议=>“https”
并禁用SSL检查,则情况并非如此line\u items\u path
更改为line\u items\u url
如果我没有弄错的话,:only_path=>false是必需的。只有在指定了:host时才可以省略它。仅供参考,这里真正的诀窍是将line\u items\u path更改为line\u items\u url,因为路径帮助程序不支持:protocol另外:仅\u path=>false对我有效。。谢谢……:)