Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Giving your user model a role

henning-koch edited this page · 12 revisions

To give your user model an Aegis role, use the has_role macro:

class User < ActiveRecord::Base

Instances of that User class can now be checked for permission like user.may_do_action?.

By default, Aegis looks for the role name in a method role_name. The return value should match a role defined in your Permissions class.

Storing the role name in the database

While the role_name property does not have to be persistent, in most cases it is convenient to add a string column role_name to your users table:

class AddRoleNameToUser < ActiveRecord::Migration

  def self.up
    add_column :users, :role_name, :string

  def self.down
    remove_column :users, :role_name



has_role comes with a number of optional parameters:

  • default: The default role name given to new User instances. Default is nil.
  • reader: The name of a method Aegis should use to look for a role name. Default is role_name.
  • permissions: The name of your permissions class as string or Class object. Default is 'Permissions'.
Something went wrong with that request. Please try again.