Will Paginate And Ajax
I recently had to implement some ajax pagination for a site. After googling for a while I found a solution, but I couldn't customize the pagination url's or I had to specify the paginator to use (will paginate's default or mine for ajax), so I came up with this solution which fulfils all my needs. First create the following class in your app/helpers.class RemoteLinkRenderer < WillPaginate::LinkRenderer
def prepare(collection, options, template)
@remote = options.delete(:remote)
super
end
protected
def page_link(page, text, attributes = {})
if @remote
@template.link_to_remote(text, {:url => url_for(page), :method => :get}.
merge(@remote), attributes)
else
@template.link_to(text, url_for(page), attributes)
end
end
end
WillPaginate::ViewHelpers.pagination_options[:renderer] = 'RemoteLinkRenderer'
will_paginate(@comments, :remote => {:update => 'comments'})