From 173f3f2a17dc80f7b993f8f8e82adac94dcd42ea Mon Sep 17 00:00:00 2001 From: Anson Hoyt Date: Thu, 6 Jun 2013 14:41:45 -0400 Subject: [PATCH] Explain how to include an attribute named "object" --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index a5386778..f4e122b4 100644 --- a/README.md +++ b/README.md @@ -255,6 +255,18 @@ end Within a serializer's methods, you can access the object being 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 authorization context to your serializer. By default, the context is the current user of your application, but this