Module: Wallaby::Paginatable
- Included in:
- ResourcesConcern, ResourcesHelper
- Defined in:
- lib/concerns/wallaby/paginatable.rb
Overview
Paginator related attributes
Instance Method Summary collapse
-
#current_paginator ⇒ Class
Model paginator for current modal class.
-
#paginate(query, options = { paginate: true }) ⇒ #each
To paginate the collection but only when either ‘page` or `per` param is given, or HTML response is requested.
- #pagination_params_for(params) ⇒ Hash, ActionController::Parameters
Instance Method Details
#current_paginator ⇒ Class
Model paginator for current modal class.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/concerns/wallaby/paginatable.rb', line 9 def current_paginator @current_paginator ||= PaginatorFinder.new( script_name: script_name, model_class: current_model_class, current_controller_class: wallaby_controller ).execute.try do |klass| Logger.debug %(Current paginator: #{klass}), sourcing: false klass.new current_model_class, collection, pagination_params_for(params) end end |
#paginate(query, options = { paginate: true }) ⇒ #each
To paginate the collection but only when either ‘page` or `per` param is given, or HTML response is requested
28 29 30 31 32 |
# File 'lib/concerns/wallaby/paginatable.rb', line 28 def paginate(query, = { paginate: true }) return query unless [:paginate] current_servicer.paginate(query, pagination_params_for(params)) end |
#pagination_params_for(params) ⇒ Hash, ActionController::Parameters
36 37 38 39 |
# File 'lib/concerns/wallaby/paginatable.rb', line 36 def pagination_params_for(params) params[:per] ||= wallaby_controller.page_size params end |