Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jgraichen/paginate-responder
A Rails pagination responder with link header support.
https://github.com/jgraichen/paginate-responder
paginate rails responder ruby
Last synced: 6 days ago
JSON representation
A Rails pagination responder with link header support.
- Host: GitHub
- URL: https://github.com/jgraichen/paginate-responder
- Owner: jgraichen
- License: mit
- Created: 2013-01-17T22:27:30.000Z (almost 12 years ago)
- Default Branch: main
- Last Pushed: 2024-12-10T12:58:20.000Z (about 1 month ago)
- Last Synced: 2024-12-29T10:12:29.190Z (13 days ago)
- Topics: paginate, rails, responder, ruby
- Language: Ruby
- Size: 97.7 KB
- Stars: 21
- Watchers: 6
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Paginate::Responder
[![Gem](https://img.shields.io/gem/v/paginate-responder?logo=rubygems)](https://rubygems.org/gems/paginate-responder)
[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/jgraichen/paginate-responder/test.yml?logo=github)](https://github.com/jgraichen/paginate-responder/actions/workflows/test.yml)
[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/jgraichen/paginate-responder?logo=codeclimate)](https://codeclimate.com/github/jgraichen/paginate-responder)A Rails pagination responder with link header support.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'paginate-responder'
```And then execute:
```session
bundle
```Or install it yourself as:
```session
gem install paginate-responder
```You will also need a pagination gem. `PaginateResponder` comes with adapters for
- [`will_paginate`](https://github.com/mislav/will_paginate),
- [`kaminari`](https://github.com/amatsuda/kaminari), and
- [`pagy`](https://github.com/ddnexus/pagy).It is recommended to use only one pagination gem at once.
## Usage
Add `Responders::PaginateResponder` to your responder chain:
```ruby
class AppResponder < Responder
include Responders::PaginateResponder
endclass MyController < ApplicationController
self.responder = AppResponder
end
```Or use it with [`plataformatec/responders`](https://github.com/plataformatec/responders):
```ruby
class MyController < ApplicationController
responders Responders::PaginateResponder
end
````PaginateResponder` will add the following link headers to
non HTML responses:- `first` First page's URL.
- `last` Last page's URL.
- `next` Next page's URL.
- `prev` Previous 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:
```ruby
class ApplicationController
def page
params[:seite].to_i # seite means page in German
end
end
```The same applies to `per_page` and `max_per_page`:
```ruby
class ApplicationController
def per_page
10
enddef max_per_page
25
end
end
```## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Add tests for your feature.
4. Add your feature.
5. Commit your changes (`git commit -am 'Add some feature'`)
6. Push to the branch (`git push origin my-new-feature`)
7. Create new Pull Request## License
[MIT License](http://www.opensource.org/licenses/mit-license.php)
Copyright © 2013-2024, Jan Graichen