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

Page per() method not working as intended #915

itskingori opened this Issue Sep 20, 2017 · 4 comments


None yet
2 participants
Copy link

itskingori commented Sep 20, 2017

If you set .per() to a value higher than config.max_per_page weirdness happens. The expectation is that the value would be limited by the value set as max.

@yuki24 yuki24 self-assigned this Sep 24, 2017


This comment has been minimized.

Copy link

yuki24 commented Sep 24, 2017

@itskingori Could you provide a test case that fails so we could understand your issue?

@yuki24 yuki24 removed their assignment Sep 25, 2017

@yuki24 yuki24 added this to the 1.2.0 milestone Sep 25, 2017


This comment has been minimized.

Copy link

itskingori commented Oct 8, 2017

@yuki24 sorry for taking a while to get back to you. That said, I'm struggling a little bit to know where to add a failing spec but ... maybe I can show you how to reproduce the problem.

Have a config like this (I'll share my entire config but my focus is on the config.max_per_page setting):

# config/initializers/kaminari.rb
Kaminari.configure do |config|
  # Default per_page value per each model.
  config.default_per_page = 30

  # Max per_page value per each model.
  config.max_per_page = 30

  # Specifying the 'inner window' size (4 by default) i.e. :window => 2
  # Example: ... 5 6 7 8 9 ...
  config.window = 5

  # Specifying the 'outer window' size (0 by default) i.e. :outer_window => 3
  # Example: 1 2 3 4 ...(snip)... 17 18 19 20
  config.outer_window = 0

  # Outer window can be separately specified by left, right (0 by default)
  # Example: 1 ...(snip)... 18 19 20
  config.left  = 0
  config.right = 0

  # Param settings
  config.param_name = :page
  config.page_method_name = :page
  config.params_on_first_page = false

Then in your controller (any controller where you want to paginate resources), have something like this:

# app/controllers/users_controller.rb
class UsersController < ApplicationController
  # GET /users
  def index
    @users = User.all.order(current_sign_in_at: :desc, email: :asc).page(page_no).per(50)

In this case, my intention was that my default .per() value to be what's in the initializer i.e. 30 ... but in the controller I wanted to override that default and use 50. So I noticed that when your .per() value is higher than config.max_per_page value, pagination goes crazy. In my case, I simply increased the value to 100.


This comment has been minimized.

Copy link

yuki24 commented Oct 10, 2017

That is intentional (see spec here). In order to override the max_per_page value on the fly, please use the #max_paginates_per method.

@yuki24 yuki24 closed this Oct 10, 2017


This comment has been minimized.

Copy link

itskingori commented Oct 10, 2017

@yuki24 right, I see. If it's intentional then that's ok. And that's for pointing me to .max_paginates_per(20).

@yuki24 yuki24 removed this from the 1.2.0 milestone Oct 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment