diff --git a/CHANGELOG.md b/CHANGELOG.md index e92e5d32..48f235fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ Misc: - [#1799](https://github.com/rails-api/active_model_serializers/pull/1799) Add documentation for setting the adapter. (@ScottKbka) - [#1909](https://github.com/rails-api/active_model_serializers/pull/1909) Add documentation for relationship links. (@vasilakisfil, @NullVoxPopuli) +- [#1959](https://github.com/rails-api/active_model_serializers/pull/1959) Add documentation for root. (@shunsuke227ono) ### [v0.10.2 (2016-07-05)](https://github.com/rails-api/active_model_serializers/compare/v0.10.1...v0.10.2) diff --git a/docs/general/serializers.md b/docs/general/serializers.md index 7e50c71c..59e4b7f2 100644 --- a/docs/general/serializers.md +++ b/docs/general/serializers.md @@ -217,7 +217,17 @@ The object being serialized. #### #root -PR please :) +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. +By default, the resource root comes from the `model_name` of the serialized object's class. + +There are several ways to specify root: +* [Overriding the root key](rendering.md#overriding-the-root-key) +* [Setting `type`](serializers.md#type) +* Specifying the `root` option, e.g. `root: 'specific_name'`, during the serializer's initialization: + +```ruby +ActiveModelSerializers::SerializableResource.new(foo, root: 'bar') +``` #### #scope