1

LocationRabl を使用して 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です。Ratingしかし今、この値を計算するために使用されたモデルの行数を Rabl ファイルでも取得したいと思います。

私は試した :

child :ratings do
    attributes :count
end

node(:ratings_count) { |m| @ratings.count }

しかし、明らかにそれは機能しません...誰かが私を助けてくれますか?

ありがとう !

4

1 に答える 1