Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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 rails获取整个当前url,但更改http协议_Ruby On Rails_Url_Parameters_Request - Fatal编程技术网

Ruby on rails rails获取整个当前url,但更改http协议

Ruby on rails rails获取整个当前url,但更改http协议,ruby-on-rails,url,parameters,request,Ruby On Rails,Url,Parameters,Request,我需要在rails视图中创建一个链接,该链接基本上使用https将用户从普通http页面带到同一页面 我现在有一些 <a href="https://<%= request.env['HTTP_HOST']%><%= request.path %>">CLICK ME!</a> <%= link_to "CLICK ME!", named_url(protocol: 'https') %> 然而,它: 不包括参数字符串 在我

我需要在rails视图中创建一个链接,该链接基本上使用https将用户从普通http页面带到同一页面

我现在有一些

 <a href="https://<%= request.env['HTTP_HOST']%><%= request.path %>">CLICK ME!</a>
<%= link_to "CLICK ME!", named_url(protocol: 'https') %>

然而,它:

  • 不包括参数字符串
  • 在我看来只是有点刻薄
是否有更好的方法将用户从http带到具有所有参数的相同相对请求路径?

尝试类似的方法

 <a href="https://<%= request.env['HTTP_HOST']%><%= request.path %>">CLICK ME!</a>
<%= link_to "CLICK ME!", named_url(protocol: 'https') %>

其中,named_url是指向您想要链接到的任何内容的路由

编辑

由于您没有命名路由,只想使用用户所在的任何页面,因此可以执行以下操作:

<%= link_to "CLICK ME!", "https://#{request.host}#{request.fullpath}" %>


您可以在此处找到有关
请求
对象的更多信息:

这就是问题所在:我没有一个名为
的url
——它应该始终与用户所在的当前页面的完整url(加上参数)相同。