Rails - how can I grab the url that was directed to the current activity in my application?
I need to see which page the request appeared on, in my controller, so that I can redirect back to it. For example, if I am on a page with a specific product (say /products/1
) and it has a link to its vendor ( /vendors/12
), I want to be able to detect inside vendors_controller that I came to that page from /products/1
. Is there an easy way in Rails to achieve this so that I can access it via params or session? thanks.
a source to share
You can also use
redirect_to request.referrer
as described here http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html
To be honest, I think this is what the previous thing does. Also see this elsewhere on S / O
Execute redirect_to correctly: return to Ruby on Rails when referrer is not available
a source to share