Search code examples
ruby-on-railsrolify

Modelling User Groups in Rails


I'm getting really confused as to how to implement a certain feature in my Rails app - basically, user groups. With one owner and several users of different types. Also, these are temporary, so no data should be stored in the User model proper.

Basically - 1 'owner' user, undefined number of 'type 1' users (each already having the role 'type 1' as an attribute independent of the group), undefined number of 'type 2' users, etc.

E.g. 1 owner, X number of plumbers (each possessing the role 'plumber'), Y number of electricians, Z no. of carpenters, etc.

Sort of like Modeling User, Group and Membership database tables, but I'm not able to figure out how to extend it further.

I'm using Rails 5 with ActiveRecord and the gem Rolify for roles.


Solution

  • Should work with a Group model having the :owner via belongs_to referencing the User.

    Then another GroupUser model with belongs_to :group and belongs_to :user and possibly some type column to serve your needs.