In the controller I have a respond_with like this:
respond_with(@layer1 , @layer2) The JSON output I need is like this:
{ "LayerOne": [ { "name": "haha", "number":"44" }, // more .... ], "LayerTwo": [ { "name": "James Bond", "score": 20 } // , .... ] } So to get the first section I write the serializer like this:
class Layer1Serializer < ActiveModel::Serializer attributes :number, :name def name object.person.name end end And I change the controller to be like this, so I can pass a ROOT so it shows in the JSON as "LayerOne"
respond_with(@Layer1, root: 'LayerOne') but remember at the beginning I had two things to pass to controller, so now I can't figure our how to do this for the second section of JSON that says "Layer2"