In my Rails 4.2 API, I'm using active model serializers for constructing json response. Suppose Post
is a model and it has many comments
and I only want to include comments which are approved/published. I'm using a scope called approved
which gives approved comments.
JSON response for post includes all comments, how do I include records which are approved and not everything. How do I construct Post serializer for that.
class PostSerializer < ActiveModel::Serializer
attributes :name, :body
has_many :comments
end