Rails 3 - 授权,为分层计划设置限制?
我正在寻找创建一个具有分层帐户计划的应用程序。我有免费帐户和高级帐户。
我正在寻找一个很好的插件来帮助我处理这种限制/授权。我正在关注 CanCan,因为它似乎是事实上的,贝茨先生很棒,但我有一个问题。
使用 CanCan,您能说限制用户完成创建操作的次数吗?我想让免费帐户只能创建一定数量的项目或其他模型对象,这可能 CanCan 吗?
不管怎样,我只是想要一些开始使用授权插件的帮助,最好是内置了用于限制活动的方法。
I'm looking to create an app that has a tiered account plan. I'd have free accounts and premium accounts.
What I'm looking for is a nice plug-in to help handle this throttling/authorization for me. I'm looking at CanCan as it seems to be the defacto, and Mr. Bates is awesome, but I had a question.
With CanCan, are you able to say, limit the times a user can complete the create action? I'd like to make it so a Free account can only create a certain number of projects or other model objects, is this possible CanCan?
Anyway, I'd just like some help getting started with Authorization plug-ins, preferable onces that have built in methods for throttling activity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能可以通过 CanCan 使用块来定义功能来实现这一点。无论如何,
我会为此创建一个模型方法。
user.has_reached_limit?
或user.on_plan_limit?
希望有帮助,
NHI
You could probably get this with CanCan using blocks to define the abilities. Something like
I would create a model method for this anyway.
user.has_reached_limit?
oruser.on_plan_limit?
Hope that helps,
NHI
限制用户创建模型记录的次数是一个问题,您通常可以通过自定义模型验证或使用控制器方法的操作过滤器来处理。我不知道有任何宝石或插件可以促进这种约束,但如果确实存在,我会很感兴趣。
Limiting the number of times a user create records of a model is a problem you can normally handle with custom model validation or by using action filters for you controller methods. I'm not aware of any gems or plugins that facilitate that sort of constraint, but I'd be interested if one does exist.