Active_model_serializers: Can't remove the model root name from my json

Created on 23 Jun 2017  路  1Comment  路  Source: rails-api/active_model_serializers

Right now I'm trying to remove the root name from my json response.

I'm getting this:
{ "list": { "accounts": [ { "id": 4, "name": "ACCOUNT", "country_id": 1 } ] } }

When I'm trying to get this:
{ "list": [ { "id": 3, "name": "VONS", "country_id": 1 } ] }

This is my controller:

render json: { list: ActiveModelSerializers::SerializableResource.new(@accounts.order(:account_name), each_serializer: AccountSerializer)}, status: :created
I'm using Rails 5 with AMS 10.0

Thanks

Most helpful comment

pass in adapter: :attributes to remove the root. Also, it would be helpful if you included the exact version.

>All comments

pass in adapter: :attributes to remove the root. Also, it would be helpful if you included the exact version.

Was this page helpful?
0 / 5 - 0 ratings