Method: Kaminari::Helpers::HelperMethods#page_entries_info
- Defined in:
- lib/kaminari/helpers/helper_methods.rb
#page_entries_info(collection, entry_name: nil) ⇒ Object
Renders a helpful message with numbers of displayed vs. total entries. Ported from mislav/will_paginate
Examples
Basic usage:
<%= page_entries_info @posts %>
#-> Displaying posts 6 - 10 of 26 in total
By default, the message will use the humanized class name of objects in collection: for instance, “project types” for ProjectType models. The namespace will be cutted out and only the last name will be used. Override this with the :entry_name
parameter:
<%= page_entries_info @posts, entry_name: 'item' %>
#-> Displaying items 6 - 10 of 26 in total
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/kaminari/helpers/helper_methods.rb', line 201 def page_entries_info(collection, entry_name: nil) entry_name = if entry_name entry_name.pluralize(collection.size, I18n.locale) else collection.entry_name(count: collection.size).downcase end if collection.total_pages < 2 t('helpers.page_entries_info.one_page.display_entries', entry_name: entry_name, count: collection.total_count) else from = collection.offset_value + 1 to = collection.offset_value + (collection.respond_to?(:records) ? collection.records : collection.to_a).size t('helpers.page_entries_info.more_pages.display_entries', entry_name: entry_name, first: from, last: to, total: collection.total_count) end.html_safe end |