如何基于类似于 stackoverflow 的点实现角色系统
我目前正在rails3中构建一个应用程序,您可以在其中完成各种事情,并获得积分,我想实现一个系统,例如stackoverflow,当您获得更多积分时,您将获得更多的管理权限。
那么在 Rails 中实现这样一个系统的最佳方法是什么?我不想让它变得太复杂。您是否会拥有大量角色并不断添加或从用户中删除它们?或者我应该比较用户拥有多少积分和他们做某事需要多少积分。不过,第二个选项的好处是,如果他们尝试在没有足够点数的情况下执行某些操作,我可能会生成错误消息。
我正在考虑使用 CanCan 来实现此目的,但我愿意接受建议。我刚刚发现 CanTango 看起来很有趣。它只是扩展了 CanCan。
I'm currently building an application in rails3 where you are given points for doing various things and I'd like to implement a system, like stackoverflow, where you get more admin rights as you get more points.
So what would be the best way to implement such a system in rails? I'd like to keep it from getting too complex. Would you just have a ton of roles and keep adding an removing them from users? Or should I just compare how many points a user has to how many they need to do something. The nice thing about the second options though is I could generate an error message if they try to do something with out enough points.
I was thinking of using CanCan for this but i'm open to suggestions. I just found CanTango which seems interesting. It just extends CanCan.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按照你最初建议的去做。这使您可以将角色与分数分离,以便您可以在以后需要时更轻松地调整对局。
此外,还有潜在的性能优势,因为您只需查找用户拥有的角色。通过基于积分的链接,您可能会遇到性能问题,具体取决于您存储赚取/扣除的积分的方式。
Do as you first suggested. That lets you decouple roles from points, so you can more easily adjust the matchups later if needed.
Also, there are potential performance benefits, because you are only looking up what roles a user has. By linking based on points, you may run into performance issues, depending on how you store the earned / deducted points.