我有一个Location使用 Rabl 以 json 格式呈现的模型。我的 index.json.rabl 看起来是这样的:
object false
collection @locations
attributes :id, :name, :address, :rating
:rating 是根据Rating模型中的记录计算得出的整数 (a Location has_many Rating, a Rating belongs_toa Location)。但现在我还想在 Rabl 文件中检索Rating用于计算该值的模型的行数。
我试过了 :
child :ratings do
attributes :count
end
和
node(:ratings_count) { |m| @ratings.count }
但显然它不起作用......有人可以帮我吗?
谢谢 !