Ajax Will_Paginate with jQuery
Recently for work I had to use ajax to reload a paginated list. I quickly found this post on using will_paginate with ajax, but the official solution uses prototype instead of jQuery, so I spent some time figuring out how to do it with jQuery in a DRY way. Here’s what I came up with (code hosted in a github gist):
When you first load up items/index, the html responder just loads the index view via the _items partial. If you click any of the ajax_will_paginate buttons, the link href will get sent via ajax, the index action will return just the _items partial, and ajax_will_paginate will update the contents of the my_items_list div. If javascript is disabled then clicking on the will_paginate links will work normally.