Merge pull request #1566 from remear/meta-docs

Add resource-level meta docs. Update top-level meta docs.
This commit is contained in:
L. Preston Sego III 2016-03-11 10:13:42 -05:00
commit 0c8abf2483

View File

@ -81,8 +81,12 @@ PR please :)
#### meta #### meta
If you want a `meta` attribute in your response, specify it in the `render` A `meta` member can be used to include non-standard meta-information. `meta` can
call: be utilized in several levels in a response.
##### Top-level
To set top-level `meta` in a response, specify it in the `render` call.
```ruby ```ruby
render json: @post, meta: { total: 10 } render json: @post, meta: { total: 10 }
@ -94,12 +98,33 @@ The key can be customized using `meta_key` option.
render json: @post, meta: { total: 10 }, meta_key: "custom_meta" render json: @post, meta: { total: 10 }, meta_key: "custom_meta"
``` ```
`meta` will only be included in your response if you are using an Adapter that supports `root`, `meta` will only be included in your response if you are using an Adapter that
as JsonAPI and Json adapters, the default adapter (Attributes) doesn't have `root`. supports `root`, e.g., `JsonApi` and `Json` adapters. The default adapter,
`Attributes` does not have `root`.
#### meta_key
PR please :) ##### Resource-level
To set resource-level `meta` in a response, define meta in a serializer with one
of the following methods:
As a single, static string.
```ruby
meta stuff: 'value'
```
As a block containing a Hash.
```ruby
meta do
{
rating: 4,
comments_count: object.comments.count
}
end
```
#### links #### links