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

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

问题描述

我们在Rails 3应用程序中使用devise 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是迄今为止最好的解决方案, a href =http://www.tonyamoyal.com/2010/07/28/rails-authentication-with-devise-and-cancan-customizing-devise-controllers/ =noreferrer> Tony的使用设计/ 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.

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

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