How to return to a particular page in a paginated index?

My scenario:

I have a paginated index of records. The user clicks edit on a record in
page 5. The edit form has different optional subforms, that return to
the edit page.

After committing the edit, show gets executed.

Clicking ‘back to index’ in show by default ends up in page 1 of the
paginated index, instead of page 5.

Is there some generic method, to pass the ‘page=5’ parameter through all
the intermediate forms to correctly build the link ‘back to index’ as
somthing like ‘index?page=5’ ?

The solution is very simple:

@records = Record.paginate(
  :page     => params[:page] || session[:rec_page],    # (2)
  :per_page => limit)
session[:rec_page] = params[:page] if params[:page]    # (1)
  • If a page was given, store it in the session cookie (1)
  • On paginateded find use the page given by params, or if not present
    that from the session cookie (2)