2
votes

I am working with ActiveModel Serializer's JSONAPI adapter and I'm trying to include a "user" resource when I serialize a "video" resource. Currently my video serializer looks something like this:

class VideoSerializer < ActiveModel::Serializer
  attributes :id, :uploaded_at, :title, :description

  belongs_to :user
  has_many :comments

  included :user
end

I've spent some time looking through the recently closed issues here: https://github.com/rails-api/active_model_serializers/issues and it looks like this feature should be complete in the latest release I just can't seem to get it to work. Does anyone see what I might be doing wrong?

1

1 Answers

3
votes

There is no included method defined in the serializer DSL. There is, though, an included adapter option, that allows one to specify which related resources should be included in the response document.

In your case (in your controller):

render json: videos, adapter: :json_api, include: 'user'