Friday, 23 August 2013

Returning count of child in json.rabl

Returning count of child in json.rabl

I have a Location model that I render in json format using Rabl. My
index.json.rabl looks that way :
object false
collection @locations
attributes :id, :name, :address, :rating
:rating is an integer calculated from records in the Rating model (a
Location has_many Rating, a Rating belongs_to a Location). But now I would
like to retrieve also in the Rabl file the number of line of the Rating
model used to calculate this value.
I tried :
child :ratings do
attributes :count
end
and
node(:ratings_count) { |m| @ratings.count }
But obviously it doesn't work... Could anyone help me there ?
Thanks !

No comments:

Post a Comment