Ruby Active Model serializer custom serializer for same model
lets say I have a method as follows
def index
applications = Application.all
render json: applications, each_serializer: ApplicationIndexSerializer, status: 200
end
now this works and it returns me my custom serializer, but if I want to add custom keys to the payload like {d开发者_开发知识库ata: application} it stops working.
however when I change the render method to
render json: {meta: {}, data: applications}, each_serializer: ApplicationIndexSerializer, status: 200
it throughs an error or the serializer does not get hit.
You probably want something like this:
render json: applications, each_serializer: ApplicationIndexSerializer, meta: {}, status: 200
精彩评论