Paginate::Responder
A Rails pagination responder with link header support.
Installation
Add this line to your application's Gemfile:
gem 'paginate-responder'You will also need a pagination gem. PaginateResponder comes with adapters for
-
will_paginate, -
kaminari, and -
pagy.
It is recommended to use only one pagination gem at once.
Usage
Add Responders::PaginateResponder to your responder chain:
class AppResponder < Responder
include Responders::PaginateResponder
end
class MyController < ApplicationController
self.responder = AppResponder
endOr use it with plataformatec/responders:
class MyController < ApplicationController
responders Responders::PaginateResponder
endPaginateResponder will add the following link headers to
non HTML responses:
-
firstFirst page's URL. -
lastLast page's URL. -
nextNext page's URL. -
prevPrevious page's URL.
next and prev page links will not be added if current page is first or last page.
Additionally, a X-Total-Pages header will be added with the total number of pages if available and a X-Total-Count header with the total number of items. This allows applications to display a progress bar or similar while fetching pages.
Override page detections and options
You can override the page detection by creating a method page in your controller that returns the page index as a numeric:
class ApplicationController
def page
params[:seite].to_i # seite means page in German
end
endThe same applies to per_page and max_per_page:
class ApplicationController
def per_page
10
end
def max_per_page
25
end
endContributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Add tests for your feature.
- Add your feature.
- Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
License
Copyright © 2013-2025, Jan Graichen