Skip to content

Commit db8ae19

Browse files
committed
add documentation to pagination feature
1 parent b508abd commit db8ae19

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ActiveModel::Serializer
22

3+
34
[![Build Status](https://travis-ci.org/rails-api/active_model_serializers.svg)](https://travis-ci.org/rails-api/active_model_serializers)
45

56
ActiveModel::Serializer brings convention over configuration to your JSON generation.
@@ -273,18 +274,6 @@ And you can change the JSON key that the serializer should use for a particular
273274
The `url` declaration describes which named routes to use while generating URLs
274275
for your JSON. Not every adapter will require URLs.
275276

276-
## Pagination
277-
278-
If you want pagination links in your response, specify it in the `render`
279-
280-
```ruby
281-
render json: @posts, pagination: true
282-
```
283-
284-
AMS relies on either Kaminari or WillPaginate. Please install either dependency by adding one of those to your Gemfile.
285-
286-
Pagination links will only be included in your response if you are using a JsonAPI adapter, the others adapters doesn't have this feature.
287-
288277
## Caching
289278

290279
To cache a serializer, call ```cache``` and pass its options.

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This is the documentation of AMS, it's focused on the **0.10.x version.**
1212
## How to
1313

1414
- [How to add root key](howto/add_root_key.md)
15+
- [How to add pagination links](howto/add_pagination_links.md) (```JSON-API``` only)
1516

1617
## Getting Help
1718

docs/howto/add_pagination_links.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# How to add pagination links
2+
3+
If you want pagination links in your response, specify it in the `render`
4+
5+
```ruby
6+
render json: @posts, pagination: true
7+
```
8+
9+
AMS relies on either `Kaminari` or `WillPaginate`. Please install either dependency by adding one of those to your Gemfile.
10+
11+
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.
12+
13+
```ruby
14+
ActiveModel::Serializer.config.adapter = :json_api
15+
```
16+
17+
ex:
18+
```json
19+
{
20+
"data": [
21+
{
22+
"type": "articles",
23+
"id": "1",
24+
"attributes": {
25+
"title": "JSON API paints my bikeshed!",
26+
"body": "The shortest article. Ever.",
27+
"created": "2015-05-22T14:56:29.000Z",
28+
"updated": "2015-05-22T14:56:28.000Z"
29+
}
30+
}
31+
],
32+
"links": {
33+
"first": "?page=1&per_page=1",
34+
"prev": "?page=2&per_page=1",
35+
"next": "?page=4&per_page=1",
36+
"last": "?page=13&per_page=1"
37+
}
38+
}
39+
```

0 commit comments

Comments
 (0)