# Going back doesn't always go, well, back

**URL:** <https://www.ruby-forum.com/t/going-back-doesnt-always-go-well-back/156013>\
**Category:** Rails\
**Created:** [December 19, 2008, 8:08am UTC](https://www.ruby-forum.com/t/going-back-doesnt-always-go-well-back/156013 "2008-12-19T08:08:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenwei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e274bd/32.png) [@kenwei](https://www.ruby-forum.com/u/kenwei)\
**Post date:** [December 19, 2008, 8:08am UTC](https://www.ruby-forum.com/t/going-back-doesnt-always-go-well-back/156013/1 "2008-12-19T08:08:23Z")

</div>

Addendum to my prior entry.

Rails scaffold creates the index, show, edit, update, destroy, create  
views.

But Rails does not provide a correct “back” method to get to the right  
spot in the index listing. Example: Index view lists 387 lines of items  
from SQL file. But using ‘back’ in show, edit, etc only goes back to TOP  
of a new index.

Using \<%= link\_to ‘Back’, items\_path %\> ONLY goes back to top of index  
view pg.  
I.e, reloads it all over again

Browser button goes back to correct point in index, you see page exactly  
where you were: top, bottom or WHEREVER IN BETWEEN.

‘Redirect\_to :back’ Rails helper won’t work with \<%= link\_to ‘Back’, …  
%\>

Also, response.env[‘HTTP\_REFERRER’] works like ‘link\_to’ - redoes index  
from top.

Must use Javascript:history.go(-1) in a link construct. \<a …\>Back  
or the browser “Back” button/context menu choice.

Why can’t rails just correctly go back one page with ‘redirect\_to  
:back’?

As it is ‘Back’ in Rails ‘link\_to’ seldom works (Unless, of course, you  
only stay at the top of the page and do nothing. Rather useless, huh?)

Sorry for the frustration.

Love Rails otherwise.

All better solutions and explanations welcomed. Can someone clear this  
up for me? Maybe I am not seeing things the “Rails” way? “RESTful” way?

Many thanks.

---

<div class="post-metadata">

**Author:** ![kenwei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e274bd/32.png) [@kenwei](https://www.ruby-forum.com/u/kenwei)\
**Post date:** [December 19, 2008, 5:21pm UTC](https://www.ruby-forum.com/t/going-back-doesnt-always-go-well-back/156013/2 "2008-12-19T17:21:26Z")

</div>

> Browser button goes back to correct point in index, you see page exactly  
> where you were: top, bottom or WHEREVER IN BETWEEN.

The browser’s back button makes no request to the server it simply pulls  
the page back from it’s local cache. A link on a page regardless of what  
it’s called makes a request.

> ‘Redirect\_to :back’ Rails helper won’t work with \<%= link\_to ‘Back’, …  
> %\>

Making a request causes a page to refresh (unless it’s an AJAX request).

This is just how the web works, it has nothing to do with Rails in  
particular.

> All better solutions and explanations welcomed. Can someone clear this  
> up for me? Maybe I am not seeing things the “Rails” way? “RESTful” way?

Pagination and AJAX have been the best solutions for this particular  
issue so far. The browser back button is the bane of web application  
development. In more ways than just this particular issue. This is  
exactly why AJAX is becoming so popular. It’s not really that AJAX is  
such a fantastic solution, it’s just the best workaround we have for a  
system that was not designed for running applications.
