Module: ActsAsIndexed::WillPaginate::Search

Included in:
ActiveRecord::Base
Defined in:
lib/will_paginate_search.rb

Instance Method Summary collapse

Instance Method Details

#paginate_search(query, options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/will_paginate_search.rb', line 7

def paginate_search(query, options)
  page = options.fetch(:page) { raise ArgumentError, ":page parameter required" }
  per_page = options.delete(:per_page) || self.per_page
  total_entries = options.delete(:total_entries)

  total_entries ||= find_with_index(query,{},{:ids_only => true}).size

  pager = ::WillPaginate::Collection.new(page, per_page, total_entries)
  options.update :offset => pager.offset, :limit => pager.per_page

  options = options.delete_if {|key, value| [:page, :per_page].include?(key) }

  pager.replace find_with_index(query, options)
  pager
end