active_model_serializers: undefined method `embed'

I’m using the 0.10.0.rc1 version because 0.9.x doesn’t work, but with this definition of the serializer:

class Api::V1::ItinerarySerializer < ActiveModel::Serializer
  attributes :id, :title

  embed :ids, include: true
  has_many :pois, serializer: Api::V1::PoiSerializer
end

I get this error:

NoMethodError (undefined method `embed' for Api::V1::ItinerarySerializer:Class):
  app/serializers/api/v1/itinerary_serializer.rb:4:in `<class:ItinerarySerializer>'
  app/serializers/api/v1/itinerary_serializer.rb:1:in `<top (required)>'
  app/controllers/api/v1/itineraries_controller.rb:29:in `update'

Embed is deprecated? How can I generate the “old” JSON including associated objects, like this:

{
  "itinerary": {
    "poi_ids": [1,4,5]
  },
  { "pois": [
    // POI serialized objects
  ]}
}

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 24 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Here’s my workaround for now, similar to @joaomdmoura above:

class PostSerializer < ActiveModel::Serializer
  attributes :id, :comment_ids

  def comment_ids
    object.comments.pluck(:id)
  end

end

+1. This is a necessity for active-model-adapter. Would really like it back.

@alexloginov in the latest version of AMS, include be used from the render call 😃