I'm using the gem 'active_model_serializers' version 0.9.3. I will minimize my model for simplicity. I have a Center model with attributes id, title and a CenterSerializer, and also CentersCollectionSerializer.
Now my question is when I instantiate from CenterSerializer to serialize a single center and call to_json on the instante i get this:
CenterSerializer.new(Center.first).to_json
"{\"center\":{\"title\":\"ExampleTitle\"}}"
which is what I should get cause i have to have the root node. The same response is returned when make curl request to the show action of the specific center. I get accepted behavior when i make a curl request to the index action of the centers getting a json response:
"{\"centers\":[
{\"title\":\"ExampleTitle\"},
{\"title\":\"ExampleTitle2\"},
{\"title\":\"ExampleTitle3\"}
}]"
But if i do
CentersCollectionSerializer.new(Center.all).to_json
i get the same thing but without the root node:
"[{\"title\":\"ExampleTitle\"},
{\"title\":\"ExampleTitle2\"},
{\"title\":\"ExampleTitle3\"}}]"
What am I doing wrong and what is happening, that he explicit to_json call on an array serializer instance gives response without root node, and the request to the index action using
respond_with @centers
(with responders gem) or
render json: @centers
gets the response with the root node?