Skip to content

Commit a9d533d

Browse files
NickOttrandobf4
authored andcommitted
Update outside_controller_use.md (#2047)
* Update outside_controller_use.md Provide example for options parameter when serializing a resource.
1 parent 58e3983 commit a9d533d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

docs/howto/outside_controller_use.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ In ActiveModelSerializers versions 0.10 or later, serializing resources outside
1010
# Create our resource
1111
post = Post.create(title: "Sample post", body: "I love Active Model Serializers!")
1212

13-
# Optional options parameters
14-
options = {}
13+
# Optional options parameters for both the serializer and instance
14+
options = {serializer: PostDetailedSerializer, username: 'sample user'}
1515

1616
# Create a serializable resource instance
1717
serializable_resource = ActiveModelSerializers::SerializableResource.new(post, options)
@@ -20,6 +20,7 @@ serializable_resource = ActiveModelSerializers::SerializableResource.new(post, o
2020
model_json = serializable_resource.as_json
2121
```
2222
The object that is passed to `ActiveModelSerializers::SerializableResource.new` can be a single resource or a collection.
23+
The additional options are the same options that are passed [through controllers](../general/rendering.md#explicit-serializer).
2324

2425
### Looking up the Serializer for a Resource
2526

0 commit comments

Comments
 (0)