mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 14:29:31 +00:00
revised docs to reflect the feedback
This commit is contained in:
parent
d153dfe2cd
commit
aeefb6a080
@ -113,25 +113,24 @@ PR please :)
|
|||||||
|
|
||||||
#### root
|
#### root
|
||||||
|
|
||||||
By default the Json Adapter `root` will follow snake case format, like so:
|
The resource root is derived from the class name of the resource being serialized.
|
||||||
|
e.g. `UserPostSerializer.new(UserPost.new)` will be serialized with the root `user_post` or `user_posts` according the adapter collection pluralization rules.
|
||||||
|
|
||||||
| resource | single root | collection root |
|
Specify the root by passing it as an argument to `render`. For example:
|
||||||
|----------|-------------|-----------------|
|
|
||||||
| UserPost | user_posts | user_post |
|
|
||||||
|
|
||||||
If you would like to change the `root` of your json, specify it in the render call:
|
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
render json: @user_post, root: "admin_post"
|
render json: @user_post, root: "admin_post", adapter: :json
|
||||||
```
|
```
|
||||||
|
|
||||||
This will produce json like:
|
This will produce serialize as:
|
||||||
```json
|
```json
|
||||||
{"admin_post": {
|
{"admin_post": {
|
||||||
"title": "how to do open source"
|
"title": "how to do open source"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
`Note: the Attributes adapter (default) does not include a resource root.`
|
||||||
|
|
||||||
#### serializer
|
#### serializer
|
||||||
|
|
||||||
PR please :)
|
PR please :)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user