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 ?