mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
added documentation for adding custom root
This commit is contained in:
parent
7d4f0c5c8a
commit
d153dfe2cd
@ -113,8 +113,25 @@ PR please :)
|
|||||||
|
|
||||||
#### root
|
#### root
|
||||||
|
|
||||||
PR please :)
|
By default the Json Adapter `root` will follow snake case format, like so:
|
||||||
|
|
||||||
|
| resource | single root | collection root |
|
||||||
|
|----------|-------------|-----------------|
|
||||||
|
| UserPost | user_posts | user_post |
|
||||||
|
|
||||||
|
If you would like to change the `root` of your json, specify it in the render call:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
render json: @user_post, root: "admin_post"
|
||||||
|
```
|
||||||
|
|
||||||
|
This will produce json like:
|
||||||
|
```json
|
||||||
|
{"admin_post": {
|
||||||
|
"title": "how to do open source"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
#### serializer
|
#### serializer
|
||||||
|
|
||||||
PR please :)
|
PR please :)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user