Module: Perron::PaginateHelper

Defined in:
app/helpers/perron/paginate_helper.rb

Instance Method Summary collapse

Instance Method Details

#paginate(scope, page: nil, **options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/perron/paginate_helper.rb', line 5

def paginate(scope, page: nil, **options)
  page ||= (params[:page] || 1).to_i
  resource_class = scope.model_class

  config = resource_class.configuration.pagination
  per_page = options[:per_page] || config.per_page
  page_path_template = options[:path_template] || config.path_template

  route = find_index_route(resource_class)
  base_path = route_path(route)

  use_query_params = Rails.env.development? || Rails.env.local?
  paginate = Paginate.new(scope, page: page, per_page: per_page, base_path: base_path, page_path_template: page_path_template, use_query_params: use_query_params)

  [paginate, paginate.items]
end