开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜