我有一个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