I have this rabl template:
object @photo attributes :id child :comments do attributes :id, :body end
What gives me this JSON answer:
{ photo: { id: 1, comments: [ { comment: { id: 1, body: 'some comment' } }, { comment: { id: 2, body: 'another comment' } } ] } }
But I want it to look like this:
{ id: 1, comments: [ { id: 1, body: 'some comment' }, { id: 2, body: 'another comment' } ] }
Why does rabl wrap each element of the array with an additional object called comment
. Thus, when I access the collection in javascript, I have to write:
var comment = image.comments[0].comment
instead:
var comment = image.comments[0]
I know that if I include :comments
in the list of attributes for the @photo
object, it will work the way I want, but when I need another level of nested associations for each comment
object, there is no way to handle this other than using child
. but it gives me a JSON response that I don't want.
Perhaps I just misunderstand all this - can someone explain or help? Thanks!
source share