23
votes

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

3 Answers

34
votes

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.

3
votes

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

0
votes

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