ruby on rails - Returning count of child in json.rabl -
i have location
model render in json format using rabl. index.json.rabl looks way :
object false collection @locations attributes :id, :name, :address, :rating
:rating integer calculated records in rating
model (a location
has_many
rating
, rating
belongs_to
location
). retrieve in rabl file number of line of rating
model used calculate value.
i tried :
child :ratings attributes :count end
and
node(:ratings_count) { |m| @ratings.count }
but doesn't work... me there ?
thanks !
if don't misunderstand mean. think want use rating.count in rabl.
you have closed answer using "node".
node(:ratings_count) { |l| l.ratings.count }
in block of node, local variable "l" 1 object of collection above.
Comments
Post a Comment