Skip to content

Commit 92e8a0a

Browse files
committed
Merge pull request #1417 from koryteg/custom_root_docs
[DOCS] added documentation for adding custom root
2 parents ac13053 + aeefb6a commit 92e8a0a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

docs/general/rendering.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,23 @@ PR please :)
113113

114114
#### root
115115

116-
PR please :)
116+
The resource root is derived from the class name of the resource being serialized.
117+
e.g. `UserPostSerializer.new(UserPost.new)` will be serialized with the root `user_post` or `user_posts` according the adapter collection pluralization rules.
118+
119+
Specify the root by passing it as an argument to `render`. For example:
120+
121+
```ruby
122+
render json: @user_post, root: "admin_post", adapter: :json
123+
```
124+
125+
This will produce serialize as:
126+
```json
127+
{"admin_post": {
128+
"title": "how to do open source"
129+
}
130+
}
131+
```
132+
`Note: the Attributes adapter (default) does not include a resource root.`
117133

118134
#### serializer
119135

0 commit comments

Comments
 (0)