Well, since it's a pagination, there's not a static page to link a "back to list" link. You could pass in the page, but that's a pain in the butt. It's much easier to do:
<%= link_to "Back up to list", request.env["HTTP_REFERER"] %>
This'll put a link back to the same page in the pagination list that you came from. Saves pains. Ends up reading the HTTP spec on headers is a helpful, in addition to some Rails source.
Ends up that "redirect_to :back" also uses the same trick. You can use that in your controller to just redirect back to whatever method called it.
I know this is an old post, but I'd like to point out that:
ReplyDelete<%= link_to "Back up to list", :back %>
will accomplish the same thing, and if there isn't a referrer, it will use the javascript:history.back() method..
Yup, thanks. This was before link_to :back was available. But it's good that people that find this will get updated.
ReplyDeleteOh..gud but you can also make it as
ReplyDelete<%= link_to 'Go Back', request.referer %>
I have a similar issue. But both :back and request.referer causes the previous page contents to reset to nil, losing what data already entered. How to avoid this?
ReplyDelete