mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Specify how to get the instance of the serializer (#1861)
[DOC] `SerializableResource#serializer` vs. `SerializableResource#serializer_instance` [ci skip]
This commit is contained in:
parent
4ff33a7ad1
commit
6567989ad7
@ -22,7 +22,7 @@ model_json = serializable_resource.as_json
|
|||||||
|
|
||||||
### Looking up the Serializer for a Resource
|
### Looking up the Serializer for a Resource
|
||||||
|
|
||||||
If you want to retrieve a serializer for a specific resource, you can do the following:
|
If you want to retrieve the serializer class for a specific resource, you can do the following:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# Create our resource
|
# Create our resource
|
||||||
@ -41,7 +41,13 @@ You could also retrieve the serializer via:
|
|||||||
ActiveModelSerializers::SerializableResource.new(post, options).serializer
|
ActiveModelSerializers::SerializableResource.new(post, options).serializer
|
||||||
```
|
```
|
||||||
|
|
||||||
Both approaches will return an instance, if any, of the resource's serializer.
|
Both approaches will return the serializer class that will be used for the resource.
|
||||||
|
|
||||||
|
Additionally, you could retrieve the serializer instance for the resource via:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
ActiveModelSerializers::SerializableResource.new(post, options).serializer_instance
|
||||||
|
```
|
||||||
|
|
||||||
## Serializing before controller render
|
## Serializing before controller render
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user