Search code examples
jsonruby-on-rails-3apirabl

RABL collection under a child node


How do I create a child which has a RABL collection inside it?

JSON needed : collection @listings should be a child of result.

{
    result: {
        listings: [
            {
                id: 1,

            },
            {
                id: 2,

            }
        ]
    }
}

RABL template with a child having collection:

object false

child @result => :result do
  collection @rents , :root => "listings", :object_root => false  

  attributes :id

end

But I get output as with the above template :

{
    result: [
        {
            id: 1
        },
        {
            id: 2
        }
    ]
}

Solution

  • I have never used RABL, but can`t you do something like this?:

    object false
    
    child @result => :result do
      child :listings
        collection @rents , :root => "listings", :object_root => false  
      end
      attributes :id
    
    end