Last Updated: February 25, 2016
· kurenn

Multiple user roles for Rails

Have you ever wondered how to handle multiple user roles?, if so you probably have been doing with a column on the user, but soon enough you will encounter with the problem of having specific columns for each role, which causes a lot of NULL columns and becomes hard to scale.


We at @icalialabs put in together a gem (acts_as_user) to help you handle multiple user roles through polymorphic associations. I provide a quick setup guide for you to start:

Getting started

ActsAsUser 1.2.1 works with rails 3 onwards. You can add it to your Gemfile with:

gem 'acts_as_user'

Then run the bundle command to install it.

After you install ActsAsUser you need to run the generator:

rails g acts_as_user:install

The generator will install in initializer which describes all the ActsAsUser configuration options, so we recommend you take a look at it. When you are done you are ready to start your user model:

For more information follow the link below: