8

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?

Rails beginner
  • 14,321
  • 35
  • 137
  • 257

2 Answers2

25

request.url.split('?').first

James
  • 4,797
  • 25
  • 29
11

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.

LouieGeetoo
  • 868
  • 2
  • 11
  • 26
mu is too short
  • 426,620
  • 70
  • 833
  • 800