link_to with:协议无效

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

 @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 %> 

如果您在应用程序中使用bartt-ssl_requirement rubygem,则可以使用ssl-url-helper明确提及http或https协议。

好处:

  1. 如果您已禁用SSL检查(在开发环境中),请按照以下方式: SslRequirement.disable_ssl_check = true ,然后传递:secure => true将不会向您的视图显式添加https链接。 如果您指定:protocol => 'https'并禁用SSL检查,则情况并非如此。

  2. 此外,没有必要在每个地方将line_items_url更改为line_items_url