[英]Rails how to request url except url params?
I am creating this link tag: 我正在创建此链接标记:
<link rel="canonical" href="<%= request.url %>" />
The problem is just it is the full url with params. 问题在于它是带有参数的完整网址。
How do I request the url without any params? 如何在没有任何参数的情况下请求网址?
request.url.split('?').first
request
is an ActionDispatch::Request and that subclasses Rack::Request. request
是一个ActionDispatch :: Request和子类Rack :: Request。 Rack::Request has a path
method that might interest you: Rack :: Request有一个你可能感兴趣的path
方法:
<%= request.path %>
If your request.url
is http://example.com/where/is?pancakes=house%3F
then request.path
should be /where/is
. 如果您的request.url
是http://example.com/where/is?pancakes=house%3F
那么request.path
应该是/where/is
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.