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

I am trying to create a web application using ruby ​​on rails. In this application, the user has several roles, such as

  • role1 = teacher
  • role2 = student
  • role3 = staff

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

for example: A student can also change his role as a teacher, and then they can teach others

When they change the role of pages, the timeline, the main page, everything should be displayed in accordance with their current role.

How can I model a database for this and how can I perform associations for this?

I am new to rubies on rails, so please help and thanks in advance!

+4
source share
2 answers

Of course! you can track the current user and then assign the user role when they switch.

Great illustration for this scenario.

If you cannot use rolify gem to add or remove roles and [cancan][3]gem to authorize.

+2
source

You can save a list of user roles, as well as track something called the current role.

0
source

Source: https://habr.com/ru/post/1659686/


All Articles