Skip to content

Commit d153dfe

Browse files
committed
added documentation for adding custom root
1 parent 7d4f0c5 commit d153dfe

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

docs/general/rendering.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,25 @@ PR please :)
113113

114114
#### root
115115

116-
PR please :)
116+
By default the Json Adapter `root` will follow snake case format, like so:
117+
118+
| resource | single root | collection root |
119+
|----------|-------------|-----------------|
120+
| UserPost | user_posts | user_post |
117121

122+
If you would like to change the `root` of your json, specify it in the render call:
123+
124+
```ruby
125+
render json: @user_post, root: "admin_post"
126+
```
127+
128+
This will produce json like:
129+
```json
130+
{"admin_post": {
131+
"title": "how to do open source"
132+
}
133+
}
134+
```
118135
#### serializer
119136

120137
PR please :)

0 commit comments

Comments
 (0)