Skip to content

Adding support for a max_per_page parameter. #23

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

Closed
wants to merge 1 commit into from

Conversation

jetheredge
Copy link

Sorry for the pull request out of nowhere, but I love the gem but I need a max_per_page parameter so that I can override the Kaminari max_per_page inside of my api controllers. Hopefully I'm not duplicating work anyone else is doing.

@jetheredge
Copy link
Author

Please let me know if there is interest in this pull request. I just would like to know if I need to pull the code into my project fully or whether this code (or something along the same lines) will ever make it into this project.

Either way, thanks for the great project!

@davidcelis
Copy link
Owner

Hey @jetheredge, sorry for taking a while to respond! First off, thanks for this contribution. I definitely want api-pagination to handle a max per page configuration; I've only held off on this because I feel like the method involved is becoming a dumping ground and I've been thinking about how I could more cleanly represent this logic. However, I don't want that to hold this back for you, so I could merge this in and then clean it up myself later before publishing any sort of release. You could bundle from git in the meantime. Does that sound okay?

@jetheredge
Copy link
Author

No problem, I just wanted to make sure you were interested in having this feature in the gem. I'm bundling from git now using my own repository (which I will continue to do so it won't change out from under me). If you want to hold off until you have a chance to clean it up that is fine with me.

davidcelis added a commit that referenced this pull request Jan 16, 2015
@davidcelis davidcelis closed this Jan 16, 2015
@jetheredge
Copy link
Author

It looks like this was only added for Grape. I wanted to point out that my commit worked for Grape as well as Kaminari/Will Paginate.

@davidcelis
Copy link
Owner

Yes, sorry about that, and sorry if you're frustrated that I ended up doing my own commit and not taking the PR... To be honest, on a second look, I didn't really see the need to implement a lot of special logic for Rails. The paginate method I have for rails doesn't really care about whats in params. The per_page option you pass in is the final word, so you could change your controller to look something like:

class MoviesController < ApplicationController
  MAX_PER_PAGE = 50

  def index
    @movies = Movie.all

    paginate json: @movies, per_page: [params[:per_page], MAX_PER_PAGE].min
  end
end

Grape didn't really have a workaround.

@jetheredge
Copy link
Author

No problem at all. I would have preferred a parameter for max_per_page, but I definitely understand the desire to keep the gem as simple as possible.

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