File tree 3 files changed +41
-12
lines changed
3 files changed +41
-12
lines changed Original file line number Diff line number Diff line change 1
1
# ActiveModel::Serializer
2
2
3
+
3
4
[ ![ Build Status] ( https://travis-ci.org/rails-api/active_model_serializers.svg )] ( https://travis-ci.org/rails-api/active_model_serializers )
4
5
5
6
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
273
274
The ` url ` declaration describes which named routes to use while generating URLs
274
275
for your JSON. Not every adapter will require URLs.
275
276
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
-
288
277
## Caching
289
278
290
279
To cache a serializer, call ``` cache ``` and pass its options.
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ This is the documentation of AMS, it's focused on the **0.10.x version.**
12
12
## How to
13
13
14
14
- [ How to add root key] ( howto/add_root_key.md )
15
+ - [ How to add pagination links] ( howto/add_pagination_links.md ) (``` JSON-API ``` only)
15
16
16
17
## Getting Help
17
18
Original file line number Diff line number Diff line change
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
+ ```
You can’t perform that action at this time.
0 commit comments