0

I'm working on the rails API application which is using ActiveModel::Serializers. The problem I faced is that I'm not able to create a single response format for all calls with usage of ActiveModel::Serializers. I tried several approach. One of them was to create an object which will be responsible for the result rendering Response with a serializer like that:

class ResponseSerializer < ActiveModel:Serializers

attributes :result, :error

end

Then to the result attribute, I'm assigning an object which has a custom serializer assigned (ObjectSerializer).

The problem is that when I'm calling explicitly render @object then the custom serializer is called, but when I'm assigning an object to the Response object which is using then ResponseSerializer class the result attribute generates the json without calling an ObjectSerializer class. Could anyone help with such issue ?

Tomasz Dubik
  • 641
  • 4
  • 6

1 Answers1

0

what about making your ObjectSerializer inherit from your ResponseSerializer ? Or use a mixin ?

m_x
  • 12,357
  • 7
  • 46
  • 60
  • I tried such approach but still ends up that I'm not able to put the error in the same node as the response if I'm inside objectSerializer class. Or the other way around. I'm not able to get the custom serializer rendered in any child node different then root. – Tomasz Dubik Nov 05 '13 at 14:28