- you need to make sure that the controller knows which link to the page that lists . we do this by passing param to the will_paginate page link generator.
- you need to make sure your js updates the correct html tag when updating the pagination of any of them. we do this by wrapping the pagination in a mood-dependent :) div tag.
- since we are separating the particle, we need to make sure that the mood, as well as the correct collection, is set in the controller and partially transmitted as local from the index representations (both html and js).
- finally make sure your ajax remote is removed after you redraw the pagination (this is a bonus)
therefore, to install instances of the controller instance, depending on the request mood parameter
- note that this code also saves you some db calls, because if you are just pagintae to sad users, you don't need to get happy or all).
- I omit @users for simplicity, never used
- I suspect that happy opportunities for sad users are just a typo
.
make sure we ship the correct local parts in parts:
# index.html.erb <%= render :partial => 'users/user', :locals => {:users => @happy_users, :mood => 'happy' } %> <%= render :partial => 'users/user', :locals => {:users => @sad_users, :mood => 'sad' } %>
make a partial mood-sensitive parameter that allows you to use a separate div tag identifier. also add mood in url request.
# users/user partial <div id='<%= "#{mood || ''}users"%>'> <% users.each do |user| %> Show some fields <% end %> <%= will_paginate users, :params => { :mood => mood } %> </div>
this js allows you to update different collections in different divs, depending on which link was clicked.
For unobtrusive ajax pagination links you need. Ruby - Rails 3 - AJAXinate Paginate and Sort
# in a generic js $(document).ready(function () { $(".pagination").find("a").livequery(function () { $(this).attr("data-remote", true); }); });
Please note that the solution should even work if javascript is not enabled and we return to html. In this case, both sections must be redrawn, which allows you to use different pages.
MODIFIED CODE THAT ALSO REVERSES GRAPHIC JS FALLBACK IN HTML
controller
redirect new views to partial local
we need to pass this here so as not to get the undefined method in partial.
then happy pages will be saved in the parameter if a sad link to the page is pressed, and vice versa.
# users/user partial <div id='<%= "#{mood || ''}users"%>'> <% users.each do |user| %> Show some fields <% end %> <%= will_paginate users, :params => { :mood => mood, :happy_page => happy_page, :sad_page => sad_page %> </div>