josevalim/active_model_serializers — pull request #18 by sbounmy (2011-12-17 03:58:54+00:00)
Title: Special Association Serializers to ArraySerializers

Like for Serializers we can define :

class CommentSerializer < ActiveModel::Serializer
attributes :id, :title, :body
end

class CustomArraySerializer < ActiveModel::ArraySerializer
class CommentSerializer < ActiveModel::Serializer
attributes :id, :title
end
end

so

CustomArraySerializer.new(Comment.all, scope).to_json

it outputs only

{
comments: [
{
id: 1,
title: "foo",
},
{
id: 2,
title: "bar",
}
]
}

instead of

{
comments: [
{
id: 1,
title: "foo",
body: "It's my first cooooomment"
},
{
id: 2,
title: "bar",
body: "Zomg I made it to my second comment"
}
]
}