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

User roles, authorisation, on specific projects

Hello, Currently I am working on a app, so far I have User (with devise) which are able to create projects. So, if user1 creates project A and project B I want him, to be able to assign user2 with role admin on project A, and user2 with moderator role on project B. I was thinking in creating a UserRoleProject link table, is it a good idea? Or if not please help me with some pointers.

The action will be something like, User1 select from a list user2, select a project from another list(that user1 created), and select the role that the user2 will have on that project.

Any user will be able to perform the same action on their projects.

Thank you

Thinking more about this, I realised that I should have the fallowing associations. User has_many Projects, Project belongs_to User, User has_many UserRole, UserRole belongs_to User, Projects has_many UserRole, UserRole belongs_to Project, Role has_many UserRole, UserRole belongs_to Role, is this right?

1 Answer

If I will use CanCan, the authorisation will have to be made on both User and Project?

Thank you