From a6fadc482f0d7ad73b1d1e209667b19ee4701bb9 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 11 Jan 2017 23:07:36 -0500 Subject: [PATCH] use correct serializer for singular embeds in api (almost fixes #998) --- app/serializers/api/v2/application_serializer.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/serializers/api/v2/application_serializer.rb b/app/serializers/api/v2/application_serializer.rb index 4345c941..d7c6d6da 100644 --- a/app/serializers/api/v2/application_serializer.rb +++ b/app/serializers/api/v2/application_serializer.rb @@ -41,7 +41,12 @@ module Api id_opts = opts.merge(key: "#{key}_id") attribute("#{attr}_id".to_sym, id_opts.merge(unless: -> { embeds.include?(key) })) - attribute(key, opts.merge(if: -> { embeds.include?(key) })) + attribute(key, opts.merge(if: -> { embeds.include?(key) })) do |serializer| + child_object = serializer.object.send(key) + child_serializer = "Api::V2::#{child_object.class.name}Serializer".constantize + resource = child_serializer.new(child_object, scope: serializer.scope.merge(embeds: [])) + resource.as_json + end end end end