Update outside_controller_use.md (#2047)

* Update outside_controller_use.md

Provide example for options parameter when serializing a resource.
This commit is contained in:
Nick Ottrando 2017-02-08 13:06:31 -08:00 committed by Benjamin Fleischer
parent 58e3983e4c
commit a9d533d916

View File

@ -10,8 +10,8 @@ In ActiveModelSerializers versions 0.10 or later, serializing resources outside
# Create our resource
post = Post.create(title: "Sample post", body: "I love Active Model Serializers!")
# Optional options parameters
options = {}
# Optional options parameters for both the serializer and instance
options = {serializer: PostDetailedSerializer, username: 'sample user'}
# Create a serializable resource instance
serializable_resource = ActiveModelSerializers::SerializableResource.new(post, options)
@ -20,6 +20,7 @@ serializable_resource = ActiveModelSerializers::SerializableResource.new(post, o
model_json = serializable_resource.as_json
```
The object that is passed to `ActiveModelSerializers::SerializableResource.new` can be a single resource or a collection.
The additional options are the same options that are passed [through controllers](../general/rendering.md#explicit-serializer).
### Looking up the Serializer for a Resource