add documentation to pagination feature

This commit is contained in:
Bruno Bacarini 2015-08-08 16:25:22 -03:00
parent 331218d1c3
commit acb6545c50
3 changed files with 40 additions and 12 deletions

View File

@ -273,18 +273,6 @@ And you can change the JSON key that the serializer should use for a particular
The `url` declaration describes which named routes to use while generating URLs
for your JSON. Not every adapter will require URLs.
## Pagination
If you want pagination links in your response, specify it in the `render`
```ruby
render json: @posts, pagination: true
```
AMS relies on either Kaminari or WillPaginate. Please install either dependency by adding one of those to your Gemfile.
Pagination links will only be included in your response if you are using a JsonAPI adapter, the others adapters doesn't have this feature.
## Caching
To cache a serializer, call ```cache``` and pass its options.

View File

@ -12,6 +12,7 @@ This is the documentation of AMS, it's focused on the **0.10.x version.**
## How to
- [How to add root key](howto/add_root_key.md)
- [How to add pagination links](howto/add_pagination_links.md) (```JSON-API``` only)
## Getting Help

View File

@ -0,0 +1,39 @@
# How to add pagination links
If you want pagination links in your response, specify it in the `render`
```ruby
render json: @posts, pagination: true
```
AMS relies on either `Kaminari` or `WillPaginate`. Please install either dependency by adding one of those to your Gemfile.
Pagination links will only be included in your response if you are using a ```JSON-API``` adapter, the others adapters doesn't have this feature.
```ruby
ActiveModel::Serializer.config.adapter = :json_api
```
ex:
```json
{
"data": [
{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever.",
"created": "2015-05-22T14:56:29.000Z",
"updated": "2015-05-22T14:56:28.000Z"
}
}
],
"links": {
"first": "?page=1&per_page=1",
"prev": "?page=2&per_page=1",
"next": "?page=4&per_page=1",
"last": "?page=13&per_page=1"
}
}
```