You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pagination links will be included in your response automatically as long
as the resource is paginated using Kaminari or WillPaginate
and if you are using a JSON-API adapter. The others adapters does not have this feature.
@@ -272,6 +272,11 @@ And you can change the JSON key that the serializer should use for a particular
272
272
273
273
The `url` declaration describes which named routes to use while generating URLs
274
274
for your JSON. Not every adapter will require URLs.
275
+
## Pagination
276
+
277
+
Pagination links will be included in your response automatically as long as the resource is paginated using [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate) and if you are using a ```JSON-API``` adapter. The others adapters does not have this feature.
278
+
279
+
For more information about it, please see in our docs [How to add pagination links](https://github.com/rails-api/active_model_serializers/blob/master/docs/howto/add_pagination_links.md)
Copy file name to clipboardExpand all lines: docs/howto/add_pagination_links.md
+12-6Lines changed: 12 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,18 @@
1
1
# How to add pagination links
2
2
3
-
If you want pagination links in your response, specify it in the `render`
3
+
Pagination links will be included in your response automatically as long as the resource is paginated and if you are using a ```JSON-API``` adapter. The others adapters does not have this feature.
4
4
5
-
```ruby
6
-
render json:@posts, pagination:true
7
-
```
5
+
If you want pagination links in your response, use [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate).
8
6
9
-
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.
12
+
#will_paginate example
13
+
@posts=Post.all.paginate(page:3, per_page:1)
14
+
render json:@posts
15
+
```
12
16
13
17
```ruby
14
18
ActiveModel::Serializer.config.adapter =:json_api
@@ -38,3 +42,5 @@ ex:
38
42
}
39
43
}
40
44
```
45
+
46
+
AMS relies on either [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate). Please install either dependency by adding one of those to your Gemfile.
0 commit comments