Module: Redmine::Pagination
- Included in:
- ApplicationController
- Defined in:
- lib/redmine/pagination.rb
Defined Under Namespace
Modules: Helper Classes: Paginator
Instance Method Summary collapse
-
#paginate(scope, options = {}) ⇒ Object
Paginates the given scope or model.
- #paginator(item_count, options = {}) ⇒ Object
Instance Method Details
#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 |
# File 'lib/redmine/pagination.rb', line 117 def paginate(scope, ={}) = .dup paginator = paginator(scope.count, ) collection = scope.limit(paginator.per_page).offset(paginator.offset).to_a return paginator, collection end |
#paginator(item_count, options = {}) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/redmine/pagination.rb', line 126 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 |