mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 06:46:50 +00:00
Corrects some markdown properties, identation and text
This commit is contained in:
parent
0994f3dda8
commit
244021d65c
23
README.md
23
README.md
@ -256,37 +256,34 @@ end
|
|||||||
If you would like to add meta information to the outputted JSON, use the `:meta`
|
If you would like to add meta information to the outputted JSON, use the `:meta`
|
||||||
option:
|
option:
|
||||||
|
|
||||||
```
|
```ruby
|
||||||
render :json => @posts, :serializer => CustomArraySerializer,
|
render :json => @posts, :serializer => CustomArraySerializer, :meta => {:total => 10}
|
||||||
:meta => {:total => 10}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The above usage of `:meta` will produce the following:
|
The above usage of `:meta` will produce the following:
|
||||||
|
|
||||||
```
|
```json
|
||||||
{
|
{
|
||||||
meta: { total: 10
|
"meta": { "total": 10 },
|
||||||
},
|
"posts": [
|
||||||
posts: [
|
|
||||||
{ "title": "Post 1", "body": "Hello!" },
|
{ "title": "Post 1", "body": "Hello!" },
|
||||||
{ "title": "Post 2", "body": "Goodbye!" }
|
{ "title": "Post 2", "body": "Goodbye!" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If you would like to to change the attribute name you can use the `meta_key` option:
|
If you would like to change the meta key name you can use the `meta_key` option:
|
||||||
|
|
||||||
```
|
```ruby
|
||||||
render :json => @posts, :serializer => CustomArraySerializer, :meta => {:total => 10}, :meta_key => 'meta_object'
|
render :json => @posts, :serializer => CustomArraySerializer, :meta => {:total => 10}, :meta_key => 'meta_object'
|
||||||
```
|
```
|
||||||
|
|
||||||
The above usage of `:meta_key` will produce the following:
|
The above usage of `:meta_key` will produce the following:
|
||||||
|
|
||||||
```
|
```json
|
||||||
{
|
{
|
||||||
meta_object: { total: 10
|
"meta_object": { "total": 10 },
|
||||||
},
|
"posts": [
|
||||||
posts: [
|
|
||||||
{ "title": "Post 1", "body": "Hello!" },
|
{ "title": "Post 1", "body": "Hello!" },
|
||||||
{ "title": "Post 2", "body": "Goodbye!" }
|
{ "title": "Post 2", "body": "Goodbye!" }
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user