sorting - How do I link back to a paginated and sorted list if that list is implemented using AJAX. I'm using Rails 3.2 -
i have list of items paginated using will_paginate , works great. implemented ajax following instructions railscast , works charm. however, now, when navigate item's page, , click "back" link, page , sorting lost.
for example, in list of books, if sort them via title , go second page, click on book, works fine. when click "back", taken first page of list without sorting. understand because url no longer updated ajax call.
how maintain pagination , sorting links ajax in rails app?
this code use implement ajax:
results.js.erb:
$("#search_results").html("<%= escape_javascript(render :partial => "layouts/search_results_list").html_safe %>");
pagination.js:
$(function() { $("#search_results").on("click", ".sort a, .pagination a", function() { $.getscript(this.href); return false; }); });
from book page, use:
request.referer
to go list.
after lots of searching , not being able find appropriate solution, turns out railscasts had answer along in different post. adding these lines pagination.js did trick:
history.pushstate(null, "", this.href); $(window).bind("popstate", function () { $.getscript(location.href); });
this changes url every ajax request. simpler other solutions contemplating.
Comments
Post a Comment