Ruby Active Model serializer custom serializer for same model

48 views Asked by At

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 {data: 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.

1

There are 1 answers

1
LawrenceWebDev On

You probably want something like this:

render json: applications, each_serializer: ApplicationIndexSerializer, meta: {}, status: 200