【发布时间】:2016-11-28 10:12:15
【问题描述】:
我该怎么做
class UserSerializer < ApplicationSerializer
attributes :id, :name. :email
has_many :posts do # I don't want to use PostSerializer
attributes :id, :title # /posts/index would show more data
has_many :comments do # like created_at, updated_at, edits, other assocs..
attributes: :id, :content
end
end
belongs_to :category do # I dont' want to user CategorySerializer
attributes :id, :name # /categories/index would show more data
end # like created_at, no. of users, associations, etc.,
end
【问题讨论】:
标签: json ruby-on-rails-5 active-model-serializers rails-api