Slide 35
Slide 35 text
ActiveModel Serializers
class PostSerializer < ActiveModel::Serializer
attributes :id, :title, :body
has_many :comments
end
class CommentSerializer < ActiveModel::Serializer
attributes :id, :text
end
# /posts/1
{ “post” : {
“id”: 1,
“title”: “Sample”,
“body”: “Sample Body”,
“comments”: [
{“id”: 1, “text”: “comment 1”}},
{“id”: 2, “text”: “comment 2”}]
}