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?
You should use request. original_url to get the current URL.
Rails' params hash contains any request parameters (URL parameters or request payload) as well as routing parameters like :controller , :action , or :id . To access only URL parameters, use request. query_parameters . Routing params are available through request.
request.url.split('?').first
request
is an ActionDispatch::Request and that subclasses Rack::Request. Rack::Request has a path
method that might interest you:
<%= request.path %>
If your request.url
is http://example.com/where/is?pancakes=house%3F
then request.path
should be /where/is
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With