Raj Raj - 3 months ago 39
Ruby Question

How to create multiple roles for single user in ruby on rails?

I am trying to create a web application using ruby on rails. In this application a user has multiple roles like

  1. role1 = teacher

  2. role2 = student

  3. role3 = staff

But the thing is a user can switch between these roles by changing account settings in the application.

eg :
Student can also change his role as teacher and then they can teach someothers

When they change the role the pages, timeline, homepage everything should be display according to their current role.

How can i model the database for this and how can i perform the associations for this ?

I am new to ruby on rails so please help & thanks in advance!


Ofcourse! you can keep track of current user and then you assign user role when they switch.

Perfect illustration for this scenario

If not you can also use rolify gem to add or remove roles and [cancan][3] gem for authorization.