From 18336d76998339a0d16b1ef156920b003e9de234 Mon Sep 17 00:00:00 2001 From: Sherwin Yu Date: Thu, 26 Dec 2013 18:01:27 -0500 Subject: [PATCH] Update README.md explaining that Serializer#filter needs to return an array --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fbac6525b..0861ded61 100644 --- a/README.md +++ b/README.md @@ -263,9 +263,9 @@ authorization context to your serializer. By default, the context is the current user of your application, but this [can be customized](#customizing-scope). -Serializers provides a method named `filter` used to determine what -attributes and associations should be included in the output. This is -typically used to customize output based on `current_user`. For example: +Serializers provides a method named `filter`, which should return an array +used to determine what attributes and associations should be included in the output. +This is typically used to customize output based on `current_user`. For example: ```ruby class PostSerializer < ActiveModel::Serializer @@ -282,7 +282,8 @@ end ``` 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 in ActiveRecord, you can declare the attribute with the different name