@@ -81,8 +81,12 @@ PR please :)
81
81
82
82
#### meta
83
83
84
- If you want a ` meta ` attribute in your response, specify it in the ` render `
85
- call:
84
+ A ` meta ` member can be used to include non-standard meta-information. ` meta ` can
85
+ be utilized in several levels in a response.
86
+
87
+ ##### Top-level
88
+
89
+ To set top-level ` meta ` in a response, specify it in the ` render ` call.
86
90
87
91
``` ruby
88
92
render json: @post , meta: { total: 10 }
@@ -94,12 +98,33 @@ The key can be customized using `meta_key` option.
94
98
render json: @post , meta: { total: 10 }, meta_key: " custom_meta"
95
99
```
96
100
97
- ` meta ` will only be included in your response if you are using an Adapter that supports ` root ` ,
98
- as JsonAPI and Json adapters, the default adapter (Attributes) doesn't have ` root ` .
101
+ ` meta ` will only be included in your response if you are using an Adapter that
102
+ supports ` root ` , e.g., ` JsonApi ` and ` Json ` adapters. The default adapter,
103
+ ` Attributes ` does not have ` root ` .
99
104
100
- #### meta_key
101
105
102
- PR please :)
106
+ ##### Resource-level
107
+
108
+ To set resource-level ` meta ` in a response, define meta in a serializer with one
109
+ of the following methods:
110
+
111
+ As a single, static string.
112
+
113
+ ``` ruby
114
+ meta stuff: ' value'
115
+ ```
116
+
117
+ As a block containing a Hash.
118
+
119
+ ``` ruby
120
+ meta do
121
+ {
122
+ rating: 4 ,
123
+ comments_count: object.comments.count
124
+ }
125
+ end
126
+ ```
127
+
103
128
104
129
#### links
105
130
0 commit comments