Skip to content

Commit 0c8abf2

Browse files
committed
Merge pull request #1566 from remear/meta-docs
Add resource-level meta docs. Update top-level meta docs.
2 parents bbebeab + 4219844 commit 0c8abf2

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

docs/general/rendering.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ PR please :)
8181

8282
#### meta
8383

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.
8690

8791
```ruby
8892
render json: @post, meta: { total: 10 }
@@ -94,12 +98,33 @@ The key can be customized using `meta_key` option.
9498
render json: @post, meta: { total: 10 }, meta_key: "custom_meta"
9599
```
96100

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`.
99104

100-
#### meta_key
101105

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+
103128

104129
#### links
105130

0 commit comments

Comments
 (0)