Skip to content

Instantly share code, notes, and snippets.

@dblock
Created July 28, 2011 13:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dblock/1111587 to your computer and use it in GitHub Desktop.
Save dblock/1111587 to your computer and use it in GitHub Desktop.
Kaminari pagination information.
# see https://github.com/amatsuda/kaminari/issues/56 and https://github.com/amatsuda/kaminari/pull/140
module Kaminari
# = Helpers
module ActionViewExtension
extend ::ActiveSupport::Concern
module InstanceMethods
def page_entries_info(collection, options = {})
collection_name = options[:collection_name] || (collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' '))
if collection.num_pages < 2
case collection.size
when 0; info = "No #{collection_name.pluralize.capitalize} found"
when 1; info = "Displaying <strong>1</strong> #{collection_name.capitalize}"
else; info = "Displaying <strong>All #{collection.size}</strong> #{collection_name.pluralize.capitalize}"
end
else
info = %{Displaying #{collection_name.pluralize.capitalize} <strong>%d&ndash;%d</strong> of <strong>%d</strong> in Total}% [
collection.offset_value + 1,
collection.offset_value + collection.length,
collection.total_count
]
end
info.html_safe
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment