Using Devise with Rails 3. Adding multiple roles?

2019-02-02 04:59发布

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.

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

  • Role1
  • Role2
  • Admin

Does devise support this? Has anybody tried this out?

3条回答
ゆ 、 Hurt°
2楼-- · 2019-02-02 05:16

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.

查看更多
Lonely孤独者°
3楼-- · 2019-02-02 05:20

You Can add Role Field to devise user for adding role then after no need to use cancan you can get reference from following git https://github.com/pervez8ktt/add-role-to-devise

查看更多
不美不萌又怎样
4楼-- · 2019-02-02 05:30

Devise is a authentication plugin and what you looking for is authorization solution. Those are quite different topics. Take a look for example on http://github.com/ryanb/cancan

查看更多
登录 后发表回答