Created
September 12, 2015 16:47
-
-
Save kikito/5bedb5fc09a81a637016 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Kaminari.configure do |config| | |
# config.default_per_page = 25 | |
# config.max_per_page = nil | |
# config.window = 4 | |
# config.outer_window = 0 | |
# config.left = 0 | |
# config.right = 0 | |
# config.page_method_name = :page | |
# config.param_name = :page | |
end | |
# Overrides for making Kaminari handle i18n pluralization correctly | |
# | |
# Remove everything below once https://github.com/amatsuda/kaminari/pull/694 is | |
# merged in Kaminari and we have updated | |
module Kaminari | |
module ActionViewExtension | |
def page_entries_info(collection, options = {}) | |
entry_name = if options[:entry_name] | |
options[:entry_name].pluralize(collection.size) | |
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 | |
first = collection.offset_value + 1 | |
last = collection.last_page? ? collection.total_count : collection.offset_value + collection.limit_value | |
t('helpers.page_entries_info.more_pages.display_entries', entry_name: entry_name, first: first, last: last, total: collection.total_count) | |
end.html_safe | |
end | |
end | |
module ActiveRecordRelationMethods | |
def entry_name(options = {}) | |
model_name.human(options.reverse_merge(default: model_name.human.pluralize(options[:count]))) | |
end | |
end | |
module MongoidCriteriaMethods | |
def entry_name(options = {}) | |
model_name.human(options.reverse_merge(default: model_name.human.pluralize(options[:count]))) | |
end | |
end | |
class PaginatableArray < Array | |
ENTRY = 'entry'.freeze | |
def entry_name(options = {}) | |
I18n.t('helpers.page_entries_info.entry', options.reverse_merge(default: ENTRY.pluralize(options[:count]))) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works like a charm! Thanks!