mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Explain how to include an attribute named "object"
This commit is contained in:
parent
edb673eea3
commit
173f3f2a17
12
README.md
12
README.md
@ -255,6 +255,18 @@ end
|
|||||||
Within a serializer's methods, you can access the object being
|
Within a serializer's methods, you can access the object being
|
||||||
serialized as `object`.
|
serialized as `object`.
|
||||||
|
|
||||||
|
Since this shadows any attribute named `object`, you can include them through `object.object`. For example:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
class VersionSerializer < ActiveModel::Serializer
|
||||||
|
attribute :version_object, key: :object
|
||||||
|
|
||||||
|
def version_object
|
||||||
|
object.object
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
You can also access the `current_user` method, which provides an
|
You can also access the `current_user` method, which provides an
|
||||||
authorization context to your serializer. By default, the context
|
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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user