module Kaminari::PaginatableWithoutCount

A module that makes AR::Relation paginatable without having to cast another SELECT COUNT query

Public Instance Methods

last_page?() click to toggle source

The page wouldn't be the last page if there's “limit + 1” record

# File lib/kaminari/activerecord/active_record_relation_methods.rb, line 106
def last_page?
  !out_of_range? && !@_has_next
end
load() click to toggle source

Overwrite AR::Relation#load to actually load one more record to judge if the page has next page then store the result in @_has_next ivar

Calls superclass method
# File lib/kaminari/activerecord/active_record_relation_methods.rb, line 87
def load
  if loaded? || limit_value.nil?
    super
  else
    set_limit_value limit_value + 1
    super
    set_limit_value limit_value - 1

    if @records.any?
      @records = @records.dup if (frozen = @records.frozen?)
      @_has_next = !!@records.delete_at(limit_value)
      @records.freeze if frozen
    end

    self
  end
end
out_of_range?() click to toggle source

Empty relation needs no pagination

# File lib/kaminari/activerecord/active_record_relation_methods.rb, line 111
def out_of_range?
  load unless loaded?
  @records.empty?
end
total_count() click to toggle source

Force to raise an exception if total_count is called explicitly.

# File lib/kaminari/activerecord/active_record_relation_methods.rb, line 117
def total_count
  raise "This scope is marked as a non-count paginable scope and can't be used in combination " \
        "with `#paginate' or `#page_entries_info'. Use #link_to_next_page or #link_to_previous_page instead."
end