mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
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:
parent
58e3983e4c
commit
a9d533d916
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user