Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Devise with Rails 3. Adding multiple roles?

Tags:

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?

like image 269
dexter Avatar asked Oct 05 '10 12:10

dexter


Video Answer


2 Answers

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.

like image 135
Tarellel Avatar answered Sep 25 '22 07:09

Tarellel


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

like image 32
mdrozdziel Avatar answered Sep 21 '22 07:09

mdrozdziel