Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing child root nodes in RABL

Tags:

I'm trying to render a pretty simple data structure using RABL, but I can't figure out how to remove the child root nodes properly. Here are my two templates.

First, the collection index template.

collection @groups, :object_root => false  attributes :id, :name child :files do   extends 'groups/_file' end 

And next, the file partial template.

object @file  attributes :id 

Those two templates end up producing the following JSON:

[    {       "id":"4f57bf67f85544e620000001",       "name":"Some Group",       "files":[          {             "file":{                "id":"4f5aa3fef855441009000007"             }          }       ]    } ] 

I want to find a way to remove the root "file" key inside of the files collection. Something like:

[    {       "id":"4f57bf67f85544e620000001",       "name":"Some Group",       "files":[          {             "id":"4f5aa3fef855441009000007"          }       ]    } ] 
like image 878
BBonifield Avatar asked Mar 12 '12 18:03

BBonifield


1 Answers

On latest versions of Rabl, you have to set this configuration if you want include_root_json to be false in all levels.

Rabl.configure do |config|   config.include_json_root = false   config.include_child_root = false end 
like image 112
mateusmaso Avatar answered Oct 27 '22 01:10

mateusmaso