mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Update README.md explaining that Serializer#filter needs to return an array
This commit is contained in:
parent
7c68ee4b3f
commit
18336d7699
@ -263,9 +263,9 @@ authorization context to your serializer. By default, the context
|
|||||||
is the current user of your application, but this
|
is the current user of your application, but this
|
||||||
[can be customized](#customizing-scope).
|
[can be customized](#customizing-scope).
|
||||||
|
|
||||||
Serializers provides a method named `filter` used to determine what
|
Serializers provides a method named `filter`, which should return an array
|
||||||
attributes and associations should be included in the output. This is
|
used to determine what attributes and associations should be included in the output.
|
||||||
typically used to customize output based on `current_user`. For example:
|
This is typically used to customize output based on `current_user`. For example:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class PostSerializer < ActiveModel::Serializer
|
class PostSerializer < ActiveModel::Serializer
|
||||||
@ -282,7 +282,8 @@ end
|
|||||||
```
|
```
|
||||||
|
|
||||||
And it's also safe to mutate keys argument by doing keys.delete(:author)
|
And it's also safe to mutate keys argument by doing keys.delete(:author)
|
||||||
in case you want to avoid creating two extra arrays.
|
in case you want to avoid creating two extra arrays. Note that if you do an
|
||||||
|
in-place modification, you still need to return the modified array.
|
||||||
|
|
||||||
If you would like the key in the outputted JSON to be different from its name
|
If you would like the key in the outputted JSON to be different from its name
|
||||||
in ActiveRecord, you can declare the attribute with the different name
|
in ActiveRecord, you can declare the attribute with the different name
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user