在 Rails 中使用 Devise 3. 添加多个角色? [英] Using Devise with Rails 3. Adding multiple roles?

查看:19
本文介绍了在 Rails 中使用 Devise 3. 添加多个角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 Rails 3 应用程序中使用设计 gem 进行身份验证.我们有多个角色,从设计的角度来看,这些角色在确认、激活和记住我的功能方面会有所不同.

We are using the devise gem for authentication in a Rails 3 application. We have multiple roles and from the devise stand-point, the roles will differ in terms of confirmation, activation and remember me functionality.

设计文档包含定义两个范围的示例.一个是用户本身,另一个是管理员角色.

The devise documentation has examples of two scopes being defined. One is the User itself and the other one is the admin role.

我可以拥有这样的东西吗?我会创建一个用户模型.然后我会创建 3 个角色:

Can I have something like this? I would create a User model. And then I would create 3 roles:

  • 角色 1
  • 角色 2
  • 管理员

设计支持吗?有人试过吗?

Does devise support this? Has anybody tried this out?

推荐答案

CanCan 是迄今为止使用 ruby​​ 角色的最佳解决方案,我建议查看 托尼使用 Devise/CanCan 创建基于角色的系统.我花了一点时间才弄明白如何解决它,但现在它为我创造了奇迹.

CanCan is by far your best solution for roles with ruby, I'd suggest checking out Tony's Usage of Devise/CanCan to create a roles based system. It took me a little bit to get exactly how to work it out, but now it works wonders for me.

这篇关于在 Rails 中使用 Devise 3. 添加多个角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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