Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Austin Klenk
Austin Klenk
4,399 Points

Cancan Role Gem RoR

I am building creating a rails app and the only thing that is holding me back on most of it is how to integrate the cancan role gem. Can you have more than one user model from devise in cancan? What I want to do is have a admin model, user model with like different roles like... Sales, Service, Parts, Technician. and lastly a Customer Model so customers can login to their account. Have any Idea? I need help.

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

First thing: you should not use CanCan, since it is a dead gem, no longer maintained. There is a variant called CanCanCan, which is an updated, still maintained version of CanCan: https://github.com/CanCanCommunity/cancancan

You can definitely have many Devise models, I'm not sure how this will behave with CanCanCan. You could also look at Pundit - I believe it's more flexible and doesn't clutter the controllers so much.

A very nice solution for implementing roles in general is the "Enum Roles" method, which you can combine with Devise and Pundit easily. http://railsapps.github.io/rails-authorization.html

That is a lot to take in if you don't know these things yet, so take your time and experiment on some simple, expendable apps.