我有一個Location
模型,我使用Rabl以json格式呈現。我index.json.rabl看起來是這樣:返回json.rabl中兒童的數量
object false
collection @locations
attributes :id, :name, :address, :rating
:評級是從記錄在Rating
模型計算出一個整數(一Location
has_many
Rating
,一個Rating
belongs_to
一個Location
)。 但是現在我想要在Rabl文件中檢索用於計算此值的Rating
模型的行數。
我想:
child :ratings do
attributes :count
end
和
node(:ratings_count) { |m| @ratings.count }
但顯然它不工作...任何人都可以幫我嗎?
謝謝!
您在模型評分中是否有屬性計數?我確定孩子(:YOUR_HAS_MANY_ASSOC){attributes:YOUR_ATTRIBUTE}正常工作。 – Bigxiang
您的意思是說我需要手動添加評分中的計數屬性?我不能只是在某個位置的收視率集合上使用.count嗎?謝謝 ! – jbihan
你是說你想在rabl中使用ratings.count? – Bigxiang