nesquena/rabl — Issue #134: Arbitrary number of levels
Author: pthaloskies
Created: 2011-10-31 10:44:41+00:00
State: open

I have been successful in getting RABL to output 2 levels deep. Very nice!

So I have:

Parent has_many :Child

Child has_many :GrandChild
belongs_to :Parent

GrandChild
belongs_to :Child

What I need to do (to an arbitrary level) is output the whole tree in JSON such that when I select a Parent id it will output all the Childs and then all the Childs will output all the GrandChilds.

Outputting Parent with Childs is no problem. How can I go the next level down (and beyond!)?

Thanks,
Martin

This code works in the Parent views in file: index.rabl
====================
object @parents

attributes :name, :credits

child :childs do
attributes :name

end
====================

And in the parents_controller.rb
====================
# GET /parents
# GET /parents.json
respond_to :json
def index
@parents = Parent.all
end