rails101
rails101

Reputation: 891

How to get request referer path?

I need the path of the referrer. I don't want the domain name. For example, if the referrer is http://www.google.com/adsense I want /adsense.

Upvotes: 89

Views: 87040

Answers (2)

chadoh
chadoh

Reputation: 4432

request.referer returns a string, but you can use Ruby's URI Module to wrap it and then simply ask it for its path:

if URI(request.referer).path == '/adsense'

Upvotes: 147

Adrian Serafin
Adrian Serafin

Reputation: 7705

You can access referer with

request.referer

Upvotes: 29

Related Questions