28.9.07

two very useful pieces of code related to will_paginate and acts_as_ferret

Related to:

  • Paginating with will_paginate _and_ ajax
  • Paginating acts_as_ferret results
Lately, I've been developing an application with huge amounts of data. For this reason i couldn't delay anymore the use of pagination on my views. I wanted to use will_paginate because it is such a nice plugin, but i was annoyed for it's lack of support for ajax. The solution was quite simple, tough, because rails makes it so easy. I only had to change the link_to calls for link_to_remote calls. I was almost there when i decided to check the repository of will paginate. There, i found that a patch by Florent Piteau was already there resolving this very issue. So here you are:

http://err.lighthouseapp.com/projects/466/tickets/67-will-paginate-patch-ajax-support

or the complete source (just change view_helpers.rb for this one, or load this file on environment.rb):

http://pastie.caboo.se/101715

Also, there is a patch to paginate ferret search results that is really easy to use. Here you are:

http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate
http://pastie.caboo.se/101716

Note: I added the

def final_pager.total_hits
total_entries()
end

bit to add compatibility with my previous api.

0 comentarios: