Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 链接到:协议isn';行不通_Ruby On Rails - Fatal编程技术网

Ruby on rails 链接到:协议isn';行不通

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://

我想有一个使用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://
而不是
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协议

优点:

  • 如果您已禁用SSL检查(在开发环境中),请按照以下方式:
    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对我有效。。谢谢……:)