Class: NextPage::Paginator
- Inherits:
-
Object
- Object
- NextPage::Paginator
- Defined in:
- lib/next_page/paginator.rb
Overview
# Paginator
Class Paginator uses the controller information to determine the model and variable name for the request, then applies a limit and offset to the query based upon the parameters or the defaults. It also extends the resource with the NextPage::PaginationAttributes mixin.
Instance Method Summary collapse
Instance Method Details
#paginate_resource(data, params, default_limit) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/next_page/paginator.rb', line 10 def paginate_resource(data, params, default_limit) default_limit ||= NextPage.configuration.default_per_page assign_pagination_attributes( data, per_page: params[:size]&.to_i || default_limit, current_page: params[:number]&.to_i || 1 ) data.limit(data.per_page).offset((data.current_page - 1) * data.per_page) end |