【发布时间】:2012-07-02 07:42:04
【问题描述】:
我有一个 Mongoid 模型,我想通过在模型和 current_user 之间实时计算的分数对结果进行排序。假设Thing有一个实例方法match_score:
def match_score(user) #can be user object too
score = 100
score -= 5 if user.min_price && !(price < user.min_price)
score -= 10 if user.max_price && !(price > user.max_price)
#... bunch of other factors...
return [score, 0].max
end
是否可以根据为特定用户返回的值对任何查询的结果进行排序?
【问题讨论】:
标签: ruby-on-rails mongodb mongoid database