如何在 Ruby on rails 中按余额对项目进行排名 [英] HOWTO rank items by balance in Ruby on rails

查看:15
本文介绍了如何在 Ruby on rails 中按余额对项目进行排名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施一个投注系统并且每个用户都有一个余额,我如何使用 activerecord 方法找到用户的排名?感谢您的帮助.

I am implementing a betting system and each user has a balance , how can i find a rank of a user using activerecord methods? thanks for your help.

推荐答案

要获取用户的排名,

Users.all(:order => "balance").index(a_particular_user)

这应该为您提供所有用户数组中特定用户的索引(排名)(按余额排序).

This should give you the index (rank) of a particular user within the array of all users (sorted by balance).

这篇关于如何在 Ruby on rails 中按余额对项目进行排名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆