How to render a json with the json_api adapter using Rails Serializer?

0

Oops, I would like to render a json using the json_api ( link ) pattern using Rails Serializer ( link ).

In my controler I'm rendering something similar to this:

render json: {'user': {name: 'Peter' }}

However, when I render this JSON, it is not output in json_api format.

In other Controllers / Models serializers are working properly, since they are using ActiveRecord, however in that case I can not pass an ActiveRecord and would like to keep the outputs of my standardized api.

** Note: I can not pass ActiveRecord on this controler because it does not have a table.

Can you help me?

    
asked by anonymous 11.05.2017 / 22:45

1 answer

0

When you render in json format you can pass some optional parameters like your user serializer as well as your adapter:

def index
  render json: @users, serializer: UserSerializer, adapter: :json_api
end

link

    
12.05.2017 / 12:25