Peter Prabu
Peter Prabu

Reputation: 1118

How to get the hostname or entire url of the visitor website in Ruby on Rails

If the user clicks a link on http://facebook.com/my_path/ that points to http://example.com/ the value of request.domain will be example.com

But in my case, I would like to get the visitor's host name facebook.com and entire url http://facebook.com/my_path/

How to get that? Any help would be appreciated. Thanks!

Upvotes: 0

Views: 393

Answers (2)

Raga
Raga

Reputation: 136

Can you try putting debugger in the controller and access that controller in your browser. When you reach the byebug shell, try to check the output of the request variable like below

(byebug) request
#<ActionDispatch::Request:0x007fe49c151840 @env={"rack.version"=>[1, 3], "rack.errors"=>#<

the output should have your referrer path if it exists

Upvotes: 0

gtbono
gtbono

Reputation: 483

Use request.referer, it is from a library called Rack, which Rails itself uses, more info here https://apidock.com/rails/Rack/Request/referer

Upvotes: 2

Related Questions