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?
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
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.
[email protected]
Gustav
Thanks, that really helped.
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-