Calling action/controller name

Dipesh Batheja 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:

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 Paul