Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3, browser back functionality

I am trying to get a back feature working on a Iphone web application.

I have looked at all the other posts about this issue, but none of them address my specific case.

This is my sequence of actions;

home page -> event page (click of a person name) -> person page

Right now, I have the <%= link_to 'Back', :back %> on both the event page and person page. With this kind of implementation, when I click on back from the person page, it takes me to the event page as expected. But when I click on back from the event page, it goes back to the person page because that is the page I came from.(whereas the expected functionality and the functionality from a browser back button would be to take me to the home page)..

Can anybody help me get this functionality in Rails?

like image 847
zacropetricopus Avatar asked Sep 03 '26 19:09

zacropetricopus


1 Answers

In the rails documentation for the link_to method you can read:

(...) use :back to link to the referrer - a JavaScript back link will be used in place of a referrer if none exists

And you can see that in the code of url_for method:

when :back
  controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
else

In your case, the referrer for the event page is the person page. Like @Zepplock pointed, you probably want to hardcode the javascript:history.back(), this is the same as clicking the Back button.

like image 117
Filipe Miguel Fonseca Avatar answered Sep 05 '26 07:09

Filipe Miguel Fonseca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!