Skip to content

Instantly share code, notes, and snippets.

@kossnocorp
Created March 1, 2014 21:38
Show Gist options
  • Save kossnocorp/9297810 to your computer and use it in GitHub Desktop.
Save kossnocorp/9297810 to your computer and use it in GitHub Desktop.
def back_or_home_path
referrer = controller.respond_to?(:request) && controller.request.env['HTTP_REFERER']
local_referrer = referrer && URI.parse(referrer).host == controller.request.host
if referrer && local_referrer
referrer
else
root_path
end
end
@rwz
Copy link

rwz commented Mar 2, 2014

There is a request.referrer method

@mkaschenko
Copy link

http://stackoverflow.com/a/8136648

URI(request.referer).host == request.host

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment