nesquena/rabl — Issue #150: Child Output gets nested too much
Author: drale2k
Created: 2012-01-25 01:26:00+00:00
State: open

Hey, i have 3 tables (location, location_bounds and location_media). All 3 are related (location has many location_bounds and location_media).

I need to for an output containing data of all 3 tables. When i use "child" for location_bounds and location_media, i get a level of nesting too much.

This is my Controller code:

```ruby
class LocationsController < ApplicationController

respond_to :json, :xml

def index
@locations = Location.all
end

def show
@location = Location.find(params[:id])
end
end
```

This is my rabl view:

````ruby
# ...views/locations/index.rabl
collection @locations

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

child :bounds do
attributes :lat, :lng
end

child :media do
attributes :kind , :url
end
````

This is the JSON output i get:

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

My problem is that is say "location_bounds" -> "location_bound" and then :lat, :lng. Same goes for "location_media". What i am looking for is "location_bounds" -> :lat, :lng and same for media.