Sha256: 570a2220a9083e61c19739b196065922056c275bd00bad0537b2635cc7230087
Contents?: true
Size: 785 Bytes
Versions: 31
Compression:
Stored size: 785 Bytes
Contents
# frozen_string_literal: true require "active_support/concern" module Decidim # Common logic to paginate resources module Paginable extend ActiveSupport::Concern OPTIONS = [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] 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
31 entries across 31 versions & 1 rubygems