nesquena/rabl — Issue #151: Can i arrange nested nodes in a custom group?
Author: drale2k
Created: 2012-01-25 11:42:54+00:00
State: open

Hi, this is my code at the moment:

````ruby
collection @locations

attributes :id, :name, :description, :lat, :lng, :updated_at

node :bounding_box do |loc|
loc.bounds.map do |lb|
{ :lat => lb.lat, :lng => lb.lng }
end
end

node :media do |loc|
loc.media.map do |media|
{ :type => media.kind, :url => media.url }
end
end
````

Produces this JOSn output:

````json
[
{
"location":{
"id":3,
"name":"Stadthalle",
"description":"Die Wiener Stadhalle",
"lat":null,
"lng":null,
"updated_at":"2012-01-24T11:28:19Z",
"status":"ok",
"bounding_box":[
{
"lat":13.133456,
"lng":13.457893
},
{
"lat":20.133456,
"lng":20.457893
},
{
"lat":8.133456,
"lng":8.457893
}
],
"media":[
{
"type":"image",
"url":"http://farm5.staticflickr.com/4069/4679448909_1264ea4668_b.jpg"
},
{
"type":"image",
"url":"http://farm5.staticflickr.com/4069/4679448909_1264ea4668_b.jpg"
},
{
"type":"video",
"url":"http://download.blender.org/peach/trailer/trailer_720p.mov"
}
{
"type":"video",
"url":"http://download.blender.org/peach/trailer/trailer_720p.mov"
}
]
}
}
]
````

Now i would like to group the "media" part in "video" and "audio", like this:

````json
"media":[
"image":[
"http://farm5.staticflickr.com/4069/4679448909_1264ea4668_b.jpg",
"http://farm5.staticflickr.com/4069/4679448909_1264ea4668_b.jpg"
],
"video":[
"http://download.blender.org/peach/trailer/trailer_720p.mov",
"http://download.blender.org/peach/trailer/trailer_720p.mov"
],
]
````