Module: Chewy::Search::Pagination::WillPaginate

Extended by:
ActiveSupport::Concern
Defined in:
lib/chewy/search/pagination/will_paginate.rb

Overview

This module provides WillPaginate support for Request It is included automatically if WillPaginate is available.

Examples:

PlacesIndex.all.paginate(page: 3, per_page: 10).order(:name)
# => <PlacesIndex::Query {..., :body=>{:size=>10, :from=>20, :sort=>["name"]}}>

Instance Method Summary collapse

Instance Method Details

#page(page) ⇒ Object



27
28
29
# File 'lib/chewy/search/pagination/will_paginate.rb', line 27

def page(page)
  paginate(page: page)
end

#paginate(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/chewy/search/pagination/will_paginate.rb', line 18

def paginate(options = {})
  @current_page = ::WillPaginate::PageNumber(options[:page] || @current_page || 1)
  @page_multiplier = @current_page - 1
  @per_page = (options[:per_page] || @per_page || ::WillPaginate.per_page).to_i

  # call Chewy::Query methods to limit results
  limit(@per_page).offset(@page_multiplier * @per_page)
end