Module: WillPaginate

Defined in:
lib/will_paginate.rb,
lib/will_paginate/finder.rb,
lib/will_paginate/version.rb,
lib/will_paginate/collection.rb,
lib/will_paginate/named_scope.rb,
lib/will_paginate/view_helpers.rb

Overview

Defined Under Namespace

Modules: Deprecation, Finder, NamedScope, VERSION, ViewHelpers Classes: Collection, InvalidPage, LinkRenderer

Class Method Summary collapse

Class Method Details

.enableObject

shortcut for enable_actionpack; enable_activerecord



13
14
15
16
# File 'lib/will_paginate.rb', line 13

def enable
  enable_actionpack
  enable_activerecord
end

.enable_actionpackObject

mixes in WillPaginate::ViewHelpers in ActionView::Base



19
20
21
22
23
24
25
26
27
# File 'lib/will_paginate.rb', line 19

def enable_actionpack
  return if ActionView::Base.instance_methods.include? 'will_paginate'
  require 'will_paginate/view_helpers'
  ActionView::Base.class_eval { include ViewHelpers }

  if defined?(ActionController::Base) and ActionController::Base.respond_to? :rescue_responses
    ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found
  end
end

.enable_activerecordObject

mixes in WillPaginate::Finder in ActiveRecord::Base and classes that deal with associations



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/will_paginate.rb', line 31

def enable_activerecord
  return if ActiveRecord::Base.respond_to? :paginate
  require 'will_paginate/finder'
  ActiveRecord::Base.class_eval { include Finder }

  # support pagination on associations
  a = ActiveRecord::Associations
  returning([ a::AssociationCollection ]) { |classes|
    # detect http://dev.rubyonrails.org/changeset/9230
    unless a::HasManyThroughAssociation.superclass == a::HasManyAssociation
      classes << a::HasManyThroughAssociation
    end
  }.each do |klass|
    klass.class_eval do
      include Finder::ClassMethods
      alias_method_chain :method_missing, :paginate
    end
  end
end

.enable_named_scope(patch = true) ⇒ Object

Enable named_scope, a feature of Rails 2.1, even if you have older Rails (tested on Rails 2.0.2 and 1.2.6).

You can pass false for patch parameter to skip monkeypatching associations. Use this if you feel that named_scope broke has_many, has_many :through or has_and_belongs_to_many associations in your app. By passing false, you can still use named_scope in your models, but not through associations.



59
60
61
62
63
64
65
66
67
# File 'lib/will_paginate.rb', line 59

def enable_named_scope(patch = true)
  return if defined? ActiveRecord::NamedScope
  require 'will_paginate/named_scope'
  require 'will_paginate/named_scope_patch' if patch

  ActiveRecord::Base.class_eval do
    include WillPaginate::NamedScope
  end
end