Sha256: 20a4e2110525eeaef7172afa5b50006d0b0171df361f57480c40ca3bc5f4bf81
Contents?: true
Size: 794 Bytes
Versions: 6
Compression:
Stored size: 794 Bytes
Contents
# frozen_string_literal: true require "active_support/concern" module Decidim # Common logic to paginate resources module Paginable extend ActiveSupport::Concern OPTIONS = [10, 20, 50, 100].freeze included do helper_method :per_page, :page_offset helper Decidim::PaginateHelper def paginate(resources) resources.page(params[:page]).per(per_page) end def per_page if OPTIONS.include?(params[:per_page]) params[:per_page].to_i elsif params[:per_page] sorted = OPTIONS.sort params[:per_page].to_i.clamp(sorted.first, sorted.last) else OPTIONS.first end end def page_offset [params[:page].to_i - 1, 0].max * per_page end end end end
Version data entries
6 entries across 6 versions & 1 rubygems