How to get request referer path?

Ruby on-RailsRuby

Ruby on-Rails Problem Overview


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.

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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'

Solution 2 - Ruby on-Rails

You can access referer with

request.referer

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionrails101View Question on Stackoverflow
Solution 1 - Ruby on-RailschadohView Answer on Stackoverflow
Solution 2 - Ruby on-RailsAdrian SerafinView Answer on Stackoverflow