Following this discussion on the forum:
Active Pagination and Active Search
# app/controllers/concerns/pagination.rb
module Pagination
extend ActiveSupport::Concern
def default_per_page
25
end
def page_no
params[:page]&.to_i || 1
end
def per_page
params[:per_page]&.to_i || default_per_page
end
def paginate_offset
(page_no-1)*per_page
end
def paginate
->(it){ it.limit(per_page).offset(paginate_offset) }
end
end
class ApplicationController < EvenMoreAbstractController
include Pagination
end
Now, in controllers, you can call:
def index
scope = Record.scoped
scope.then(&paginate)
end
# which is a shortcut for
def index
scope = Record.scoped
scope.limit(per_page).offset(paginate_offset)
end
The params are :page
and :per_page
.
https://github.com/kaminari/kaminari
Creates .page
scope on AR models. Okay.
User.page(1)