mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
add documentation to pagination feature
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
39
docs/howto/add_pagination_links.md
Normal file
39
docs/howto/add_pagination_links.md
Normal 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"
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user