The roar-rails gem can be used to generate custom REST representations of resources for your Rails application. If you have an app with any sort of nested resources, then you may not have many found examples of representing the layers of resources. Here is one that I've found works and is mostly straight forward.
As the routes file and models show, it is just a simple has_many
/belongs_to
relationship. You likely want to show representations of the resources: People
, Person
, Pets
for Person
, and Pet
. Writing representers for People
, Person
, and Pet
are simple enough, and the roar-rails
documentation explains it. There are multiple ways to represent the Pets for a Person; which is a resource in its own right. Because it is a resource, it should have its own representation: PersonPetsRepresenter
.
A simple way is to respond_with @person
and then read the #pets
relation in the