Skip to content

Releases: davidcelis/api-pagination

3.0.2

23 May 01:32
Compare
Choose a tag to compare
  • Fix an issue where paginate_with would raise an exception in Rails (#11)
  • Fix an issue where the per_page option could not be overridden in Grape (#12)

3.0.1

01 May 21:16
Compare
Choose a tag to compare
  • Fix an issue when using will_paginate with sequel
  • Fix an issue with a default per_page not being set in Grape

3.0.0

17 Apr 19:27
Compare
Choose a tag to compare

The interface of Rails has changed to avoid using after_filter, as that approach didn't really work:

class MoviesController < ApplicationController
  # GET /movies
  def index
    movies = Movie.all # Movie.scoped if using ActiveRecord 3.x

    paginate json: movies
  end

  # GET /movies/:id/cast
  def cast
    actors = Movie.find(params[:id]).actors

    # Override how many Actors get returned. If unspecified,
    # params[:per_page] (which defaults to 25) will be used.
    paginate json: actors, per_page: 10
  end
end

The interface for Grape has also changed a bit to be more consistent with the
new Rails interface. Namely, any per_page option specified to the route-level
paginate call overrides params[:per_page]:

class MoviesAPI < Grape::API
  format :json

  desc 'Return a paginated set of movies'
  paginate
  get do
    # This method must take an ActiveRecord::Relation
    # or some equivalent pageable set.
    paginate Movie.all
  end

  route_param :id do
    desc "Return one movie's cast, paginated"
    # Override how many Actors get returned. If unspecified,
    # params[:per_page] (which defaults to 25) will be used.
    paginate per_page: 10
    get :cast do
      paginate Movie.find(params[:id]).actors
    end
  end
end

Miscellaneous fixes:

  • The default per_page is now 25.
  • Fix issue with the Rails response body not automatically paging

2.1.0

13 Feb 19:09
Compare
Choose a tag to compare
  • Populate a Total header based on the total number of entries in a collection

v2.0.0

16 Dec 03:44
Compare
Choose a tag to compare

2.0.0

  • Add support for Grape pagination
  • It is no longer necessary to explicitly call paginate, page, or per on your collection. Instead, the calls to paginate will do it for you based on your :per_page setting:
# Rails
class MoviesController
  after_filter only: [:index] { paginate(:movies) } 

  def index
    params[:per_page] = 25
    @movies = Movie.all

    render json: @movies
  end
end

# Grape
class MoviesAPI < Grape::API
  format :json

  desc 'Return a paginated set of movies'
  paginate per_page: 25
  get :numbers do
    movies = Movie.all

    paginate movies
  end
end
  • The default setting for :per_page is 10 and can be overridden such as above.

v1.1.1

05 Jul 07:05
Compare
Choose a tag to compare

1.1.1

  • Fix an issue where empty Link headers would be sent (#2)