Sha256: a2e8f2cc7608ca4c1ae437ee5198329e7eb9df8b7ce54977f93d357937310d9f
Contents?: true
Size: 789 Bytes
Versions: 13
Compression:
Stored size: 789 Bytes
Contents
module Admin::Resources::PaginationHelper def admin_paginate params[:per_page] ||= @resource.typus_options_for(:per_page) params[:per_page] = params[:per_page].to_i params[:offset] ||= 0 params[:offset] = params[:offset].to_i next_offset = params[:offset] + params[:per_page] previous_offset = params[:offset] - params[:per_page] options = {} current_page = (params[:offset].to_f / params[:per_page]) + 1 num_pages = (@resource.count.to_f / params[:per_page]).ceil unless current_page >= num_pages options[:next] = params.merge(offset: next_offset) end if previous_offset >= 0 options[:previous] = params.merge(offset: previous_offset) end render "admin/resources/pagination", { :options => options } end end
Version data entries
13 entries across 13 versions & 1 rubygems