# Calling action/controller name

**URL:** <https://www.ruby-forum.com/t/calling-action-controller-name/73171>\
**Category:** Rails\
**Created:** [October 22, 2006, 2:28pm UTC](https://www.ruby-forum.com/t/calling-action-controller-name/73171 "2006-10-22T14:28:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dipeshbatheja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dipeshbatheja](https://www.ruby-forum.com/u/dipeshbatheja)\
**Post date:** [October 22, 2006, 2:28pm UTC](https://www.ruby-forum.com/t/calling-action-controller-name/73171/1 "2006-10-22T14:28:52Z")

</div>

I have created a back link on a page, which takes you back to the page  
from where you came. The problem is that the user could come from many  
different pages. So i can’t hard code the link to a single page. Is  
there a way to know which action/controller called the current  
action/controller, so that I can use their names in my back link?

---

<div class="post-metadata">

**Author:** ![dipeshbatheja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dipeshbatheja](https://www.ruby-forum.com/u/dipeshbatheja)\
**Post date:** [October 23, 2006, 12:29am UTC](https://www.ruby-forum.com/t/calling-action-controller-name/73171/2 "2006-10-23T00:29:34Z")

</div>

Dipesh B. wrote:

> I have created a back link on a page, which takes you back to the page  
> from where you came. The problem is that the user could come from many  
> different pages. So i can’t hard code the link to a single page. Is  
> there a way to know which action/controller called the current  
> action/controller, so that I can use their names in my back link?

One of my colleagues posted on a good way to implement jumpback  
functionality  
in rails. It was a while ago though…

Check it out here: [http://rails.co.za/articles/2006/03/20/jumpback](http://rails.co.za/articles/2006/03/20/jumpback)

A different way, which may be better, is to use the :back option of the  
standard redirect\_to  
method. This redirects the user to the ‘HTTP\_REFERRER’, aka the page the  
user was just at.

you could do something like the following:

in your controller, in this instance: welcome\_controlller:

def back  
redirect\_to :back  
end

then i’d add the following helper to your application\_helper

def link\_back(text=‘back’)  
link\_to text, :controller =\> ‘welcome’, :action =\> ‘back’  
end

and then you can use it in your views as:

\<%= link\_back ‘go back where you came from’ %\>

Hope this helps!

Cheery-o  
Gustav P.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![dipeshbatheja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dipeshbatheja](https://www.ruby-forum.com/u/dipeshbatheja)\
**Post date:** [October 23, 2006, 5:17am UTC](https://www.ruby-forum.com/t/calling-action-controller-name/73171/3 "2006-10-23T05:17:51Z")

</div>

Gustav

Thanks, that really helped.

---

<div class="post-metadata">

**Author:** ![dipeshbatheja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dipeshbatheja](https://www.ruby-forum.com/u/dipeshbatheja)\
**Post date:** [February 7, 2007, 1:02am UTC](https://www.ruby-forum.com/t/calling-action-controller-name/73171/4 "2007-02-07T01:02:33Z")

</div>

Hi,  
I tried the steps mentioned above. ☹ But my page just stays at the  
current page, doesn’t seem to go back. Any thoughts?🙂

In addition, I am looking to also send back the user to the same page  
in case the previous view was paginated. Any thoughts on this as well?

On Oct 22 2006, 7:17 pm, Dipesh B. \<rails-mailing-l…@andreas-
