Skip to content

Commit

Permalink
Update outside_controller_use.md (rails-api#2047)
Browse files Browse the repository at this point in the history
* Update outside_controller_use.md

Provide example for options parameter when serializing a resource.
  • Loading branch information
NickOttrando authored and bf4 committed Feb 8, 2017
1 parent 58e3983 commit a9d533d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/howto/outside_controller_use.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit a9d533d

Please sign in to comment.