How to retrieve the *referring* action/controller

Hi there,

I'm posting because I didn't find the answer using search engines:

How do I get the name of the action and/or controller that have sent the user to the current page?

(I know one can access the *current* action/controller using controller.controller_name and controller.action_name, but I need to retrieve the the *referring* action/controller, meaning "the one before"...)

Thanks a lot for any help! Tom

You can't directly find the referring action/controller, but you can get the referring URL.

request.referrer

The problem in trying to determine the referring action from this is you have no knowledge of the verb used on the referring URL. For example /products could be the products index action (GET), or the create action (POST). HTTP is stateless by nature, so the only way to know the action truly would be to hack your own state into the session. You could then set the last action in the cookie as an after_filter, but that would be rather heavy handed. Perhaps it's better to review why you need that info & from there come up with a different solution.

Niels

Thanks, Niels!