在我的标签里我有:
rating_score => The current score
ratings => The number of ratings which led to the score我想创建一个名为rating的“伪”列,它在model中是(rating_score/rating)。我可以在我的控制器中使用它在我的视图中和之后进行排序。
我应该如何在我的模型中创建它?
发布于 2011-04-25 04:36:04
请注意,您不能让SQL查询按虚拟属性对结果进行排序。你能做的就是在你的模型中像这样定义方法:
def rating
rating_scope / ratings
end并根据值以拼音形式对结果集进行排序:
results.sort_by(&:rating)https://stackoverflow.com/questions/5773035
复制相似问题