Module: Redmine::Pagination
- Included in:
- ApplicationController
- Defined in:
- lib/redmine/pagination.rb
Overview
Defined Under Namespace
Modules: Helper Classes: Paginator
Instance Method Summary collapse
- #deprecated_paginate(arg, finder_options, options = {}) ⇒ Object
-
#paginate(scope, options = {}) ⇒ Object
Paginates the given scope or model.
- #paginator(item_count, options = {}) ⇒ Object
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, , ={}) 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() paginate(scope, ) 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, ={}) = .dup = .extract!( :conditions, :order, :joins, :include, :select ) if scope.is_a?(Symbol) || .values.compact.any? return deprecated_paginate(scope, , ) end paginator = paginator(scope.count, ) 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, ={}) .assert_valid_keys :parameter, :per_page page_param = [:parameter] || :page page = (params[page_param] || 1).to_i per_page = [:per_page] || per_page_option Paginator.new(item_count, per_page, page, page_param) end |