views:

29

answers:

1

I have a simple Rails app and for example purposes we'll say I have a customer model. If I have 1000 customers and I'm on page 6 when I click to view the details on a specific customer, what would be the best method so when I click a "Return to list" link, that it takes me back to page 6 and possibly even does a scroll to an anchor that's associated with the row that the customer was located on.

I'm using will_paginate and everything is very basic CRUD pages at the moment.

+1  A: 

You need to specify the return page as a query parameter in the link_to method. By default will_paginate calls this parameter page.

Something like:

<%= link_to 'Return to list', :controller => 'customers', :page => 6 %>

Or if you're using RESTful routes:

<%= link_to 'Return to list', customers_path(:page => 6) %>

With an anchor:

<%= link_to 'Return to list',
      customers_path(:page => 6, :anchor => 'customer15') %>
John Topley
I ended up with this solution immediately after posting, glad to see an answer with the solution I came up with!
mwilliams