Skip to content

Commit ce8dd36

Browse files
shunsuke227onoYohan Robert
authored andcommitted
Add documentation for root (#1959)
1 parent cb20b95 commit ce8dd36

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Misc:
3434

3535
- [#1799](https://github.com/rails-api/active_model_serializers/pull/1799) Add documentation for setting the adapter. (@ScottKbka)
3636
- [#1909](https://github.com/rails-api/active_model_serializers/pull/1909) Add documentation for relationship links. (@vasilakisfil, @NullVoxPopuli)
37+
- [#1959](https://github.com/rails-api/active_model_serializers/pull/1959) Add documentation for root. (@shunsuke227ono)
3738

3839
### [v0.10.2 (2016-07-05)](https://github.com/rails-api/active_model_serializers/compare/v0.10.1...v0.10.2)
3940

docs/general/serializers.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,17 @@ The object being serialized.
217217

218218
#### #root
219219

220-
PR please :)
220+
Resource root which is included in `JSON` adapter. As you can see at [Adapters Document](adapters.md), `Attribute` adapter (default) and `JSON API` adapter does not include root at top level.
221+
By default, the resource root comes from the `model_name` of the serialized object's class.
222+
223+
There are several ways to specify root:
224+
* [Overriding the root key](rendering.md#overriding-the-root-key)
225+
* [Setting `type`](serializers.md#type)
226+
* Specifying the `root` option, e.g. `root: 'specific_name'`, during the serializer's initialization:
227+
228+
```ruby
229+
ActiveModelSerializers::SerializableResource.new(foo, root: 'bar')
230+
```
221231

222232
#### #scope
223233

0 commit comments

Comments
 (0)