mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
add documentation to pagination feature
This commit is contained in:
parent
331218d1c3
commit
acb6545c50
12
README.md
12
README.md
@ -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.
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
Reference in New Issue
Block a user