Skip to content

Commit 297e1f7

Browse files
Jwan622remear
authored andcommitted
Update docs regarding overriding the root key
1 parent 88d4fe5 commit 297e1f7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

docs/general/rendering.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,14 @@ link(:link_name) { url_for(controller: 'controller_name', action: 'index', only_
211211

212212
PR please :)
213213

214-
#### root
214+
#### Overriding the root key
215215

216-
The resource root is derived from the class name of the resource being serialized.
216+
Overriding the resource root only applies when using the JSON adapter.
217+
218+
Normally, the resource root is derived from the class name of the resource being serialized.
217219
e.g. `UserPostSerializer.new(UserPost.new)` will be serialized with the root `user_post` or `user_posts` according the adapter collection pluralization rules.
218220

219-
Specify the root by passing it as an argument to `render`. For example:
221+
When using the JSON adapter in your initializer (ActiveModelSerializers.config.adapter = :json), or passing in the adapter in your render call, you can specify the root by passing it as an argument to `render`. For example:
220222

221223
```ruby
222224
render json: @user_post, root: "admin_post", adapter: :json
@@ -230,7 +232,7 @@ This will be rendered as:
230232
}
231233
}
232234
```
233-
Note: the `Attributes` adapter (default) does not include a resource root.
235+
Note: the `Attributes` adapter (default) does not include a resource root. You also will not be able to create a single top-level root if you are using the :json_api adapter.
234236

235237
#### serializer
236238

0 commit comments

Comments
 (0)