Nonos
Nonos

Reputation: 2518

Getting the caller URL in Rails

I'm trying to determine the URL of the request caller in a Rails controller.

I tried using request.env['HTTP_REFERER'] but it's sometimes null. Any ideas?

Thanks in advance.

Upvotes: 1

Views: 1537

Answers (2)

Srdjan Pejic
Srdjan Pejic

Reputation: 8212

You're just going to have to deal with the fact that sometimes there will be no requesting URL. as a commenter said, if a user types the URL in or if it's a bookmark, the referrer field will be empty. And those are just legitimate, everyday cases.

Don't depend on that field being there.

Upvotes: 0

Related Questions