Module: RailsPaginationUltimate::ActionViewHelper
- Defined in:
- lib/rails_pagination_ultimate/action_view_helper.rb
Instance Method Summary collapse
- #page_entries_info(collection, options = {}) ⇒ Object
- #paginate(collection, options = {}) ⇒ Object
- #per_page_select(collection, options = {}) ⇒ Object
Instance Method Details
#page_entries_info(collection, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rails_pagination_ultimate/action_view_helper.rb', line 12 def page_entries_info(collection, = {}) entry_name = [:entry_name] || collection.model_name.human.downcase entry_name = entry_name.pluralize if collection.total_count != 1 if collection.total_pages == Float::INFINITY first = collection.offset_value + 1 last = collection.offset_value + collection.length return I18n.t("rails_pagination_ultimate.info.without_count", first: first, last: last, entry_name: entry_name).html_safe end if collection.total_pages < 2 I18n.t("rails_pagination_ultimate.info.all", total: collection.total_count, entry_name: entry_name).html_safe else first = collection.offset_value + 1 last = [collection.offset_value + collection.limit_value, collection.total_count].min I18n.t("rails_pagination_ultimate.info.other", first: first, last: last, total: collection.total_count, entry_name: entry_name).html_safe end end |
#paginate(collection, options = {}) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/rails_pagination_ultimate/action_view_helper.rb', line 5 def paginate(collection, = {}) return unless collection.respond_to?(:total_pages) paginator = Paginator.new(self, collection, ) paginator.render end |
#per_page_select(collection, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rails_pagination_ultimate/action_view_helper.rb', line 31 def per_page_select(collection, = {}) choices = [:choices] || [10, 25, 50, 100] current_per = collection.limit_value template.content_tag(:div, class: "rp-per-page-container #{[:class]}") do template.concat template.content_tag(:span, [:label] || "Show", class: "rp-label") template.concat template.select_tag(:per, template.(choices, current_per), class: "rp-select", onchange: "const url = new URL(window.location.href); url.searchParams.set('per', this.value); url.searchParams.set('page', 1); window.location.href = url.toString();") end end |