Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add page_access_method and per_page_access_method #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

edugonch
Copy link

@edugonch edugonch commented Aug 16, 2018

What does this PR do?

  • Allows to user other methods name, for example, if you use kaminari and will_paginate together and you need to change the pagination method name on kaminari.

Example
/config/initializers/kaminari_config.rb

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_kaminari
  # config.param_name = :page
  # config.params_on_first_page = false
end

/config/initializers/pager_api.rb

PagerApi.setup do |config|

  # Pagination Handler
  # User this option to meet your pagination handler, whether is :kaminari or :will_paginate
  config.pagination_handler = :kaminari

  config.page_access_method = :page_kaminari

  # Includes Pagination information on Meta
  #
  config.include_pagination_on_meta = true

  # Includes Pagination information on a Link Header
  #
  # config.include_pagination_headers = true

  # Set the Total-Count Header name
  # config.total_count_header = "X-Total-Count"
end

@kurenn
Copy link
Member

kurenn commented Apr 30, 2019

This seems practical! Let me review it and come back to you!


# per page access method
mattr_accessor :per_page_access_method
@@per_page_access_method = :per
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can rename this to per_page to match a default value for Kaminari and WillPaginate, how does that sound?

@@ -66,7 +66,7 @@ def paginate_collection(collection, options = {})
options[:page] = params[:page] || 1
options[:per_page] = options.delete(:per_page) || params[:per_page] || ::Kaminari.config.default_per_page

collection.page(options[:page]).per(options[:per_page])
collection.send(PagerApi.page_access_method, options[:page]).send(PagerApi.per_page_access_method, options[:per_page])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a meta which I think you can update to meet this two accessors, what do you think?

Also there can you provide the update for the will_paginate driver module to meet this as well?

Thanks for the collaboration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants