# How to retrieve the \*referring\* action/controller

**URL:** <https://www.ruby-forum.com/t/how-to-retrieve-the-referring-action-controller/182392>\
**Category:** Rails\
**Created:** [January 27, 2010, 1:55pm UTC](https://www.ruby-forum.com/t/how-to-retrieve-the-referring-action-controller/182392 "2010-01-27T13:55:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [January 27, 2010, 1:55pm UTC](https://www.ruby-forum.com/t/how-to-retrieve-the-referring-action-controller/182392/1 "2010-01-27T13:55:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [January 27, 2010, 5:32pm UTC](https://www.ruby-forum.com/t/how-to-retrieve-the-referring-action-controller/182392/2 "2010-01-27T17:32:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [January 27, 2010, 5:43pm UTC](https://www.ruby-forum.com/t/how-to-retrieve-the-referring-action-controller/182392/3 "2010-01-27T17:43:22Z")

</div>

Thanks, Niels!
