Module: WillPaginate::Finder

Defined in:
lib/will_paginate/finder.rb

Overview

A mixin for ActiveRecord::Base. Provides per_page class method and hooks things up to provide paginating finders.

Find out more in WillPaginate::Finder::ClassMethods

Global options for finder

Options for the finder are optional and get their default values from the WillPaginate::Finder.custom_counters hash. You can write to this hash to override default options on the global level:

# This is an example for acts_as_paranoid.
WillPaginate::Finder.custom_counters.merge!({
  'find_with_deleted' => 'count_with_deleted',
  'find_only_deleted' => 'count_only_deleted'
})

By putting this into “config/initializers/will_paginate.rb” (or simply environment.rb in older versions of Rails) you can easily tell WillPaginate how to count total entries when you’re using some kind of custom finder.

Also, if you’re using a plugin which adds it’s own custom finder but doesn’t include a matching counter, you can easily implement it yourself and configure WillPaginate to be able to use it.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

@@custom_counters =

Custom counters that can be used to extend will_paginate to work ok with other plugins like acts_as_paranoid which add their own custom finders with corresponding counters too.

{}

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/will_paginate/finder.rb', line 34

def self.included(base)
  base.extend ClassMethods
  class << base
    alias_method_chain :method_missing, :paginate
    # alias_method_chain :find_every,     :paginate
    define_method(:per_page) { 30 } unless respond_to?(:per_page)
  end
end