I have three tables users,posts and comments. The serializer of post is
class PostSerializer < ActiveModel::Serializer
attributes :id, :content, :like, :created_at, :updated_at
attributes :user
has_many :comments
def user
object.user
end
end
Comments have the following attributes.The comment serializer is
class CommentSerializer < ActiveModel::Serializer
attributes :id, :comment, :created_at, :updated_at
attributes :user
attributes :post
belongs_to :user
belongs_to :post
def user
object.user
end
def post
object.post
end
end
I need the attributes of comments when I print the JSON of posts.