Module: WillPaginate::ActiveRecord::Pagination

Included in:
WillPaginate::ActiveRecord
Defined in:
lib/will_paginate/active_record.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) page(num)



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/will_paginate/active_record.rb', line 160

def page(num)
  rel = if ::ActiveRecord::Relation === self
    self
  elsif !defined?(::ActiveRecord::Scoping) or ::ActiveRecord::Scoping::ClassMethods.method_defined? :with_scope
    # Active Record 3
    scoped
  else
    # Active Record 4
    all
  end

  rel = rel.extending(RelationMethods)
  pagenum = ::WillPaginate::PageNumber(num.nil? ? 1 : num)
  per_page = rel.limit_value || self.per_page
  rel = rel.offset(pagenum.to_offset(per_page).to_i)
  rel = rel.limit(per_page) unless rel.limit_value
  rel.current_page = pagenum
  rel
end

- (Object) paginate(options)



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/will_paginate/active_record.rb', line 144

def paginate(options)
  options  = options.dup
  pagenum  = options.fetch(:page) { raise ArgumentError, ":page parameter required" }
  per_page = options.delete(:per_page) || self.per_page
  total    = options.delete(:total_entries)

  count_options = options.delete(:count)
  options.delete(:page)

  rel = limit(per_page.to_i).page(pagenum)
  rel = rel.apply_finder_options(options) if options.any?
  rel.wp_count_options = count_options    if count_options
  rel.total_entries = total.to_i          unless total.blank?
  rel
end