Module: Redmine::Pagination

Included in:
ApplicationController
Defined in:
lib/redmine/pagination.rb

Overview

Since:

  • 2.3.0

Defined Under Namespace

Modules: Helper Classes: Paginator

Instance Method Summary collapse

Instance Method Details

#deprecated_paginate(arg, finder_options, options = {}) ⇒ Object

Deprecated.

Removed at 3.4.0



136
137
138
139
140
141
# File 'lib/redmine/pagination.rb', line 136

def deprecated_paginate(arg, finder_options, options={})
  ActiveSupport::Deprecation.warn "#paginate with a Symbol and/or find options is depreceted and will be removed. Use a scope instead."
  klass = arg.is_a?(Symbol) ? arg.to_s.classify.constantize : arg
  scope = klass.scoped(finder_options)
  paginate(scope, options)
end

#paginate(scope, options = {}) ⇒ Object

Paginates the given scope or model. Returns a Paginator instance and the collection of objects for the current page.

Options:

:parameter     name of the page parameter

Examples:

@user_pages, @users = paginate User.where(:status => 1)


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/redmine/pagination.rb', line 117

def paginate(scope, options={})
  options = options.dup
  finder_options = options.extract!(
    :conditions,
    :order,
    :joins,
    :include,
    :select
  )
  if scope.is_a?(Symbol) || finder_options.values.compact.any?
    return deprecated_paginate(scope, finder_options, options)
  end

  paginator = paginator(scope.count, options)
  collection = scope.limit(paginator.per_page).offset(paginator.offset).to_a

  return paginator, collection
end

#paginator(item_count, options = {}) ⇒ Object



143
144
145
146
147
148
149
150
# File 'lib/redmine/pagination.rb', line 143

def paginator(item_count, options={})
  options.assert_valid_keys :parameter, :per_page

  page_param = options[:parameter] || :page
  page = (params[page_param] || 1).to_i
  per_page = options[:per_page] || per_page_option
  Paginator.new(item_count, per_page, page, page_param)
end