Created
September 30, 2010 13:39
-
-
Save aermolaev/604581 to your computer and use it in GitHub Desktop.
Revisions
-
aermolaev created this gist
Sep 30, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ module ActsAsFerret class SearchResults # To prevent WillPaginate warning attr_reader :total_pages end module ClassMethods def paginate_search(query, options = {}, find_options = {}) page, per_page = wp_parse_options(options) offset = (page.to_i - 1) * per_page hits = total_hits(query) hits = 1 if hits == 0 f_options = find_options.merge(:offset => offset, :limit => per_page) result = find_with_ferret(query, { :offset => 0, :limit => hits }, f_options) WillPaginate::Collection.new(page, per_page, result.total_hits).tap do |pager| pager.replace(result) end end end end