To add simple roles feature to a model (like user) in a integer field.
include in Gemfile:
gem 'roles-field'
in a model with a field named 'roles_mask' (you can use any other field name):
# generate a model with a integer field
create_table :users, :force => true do |t|
t.column :roles_mask, :integer
end
class User < ActiveRecord::Base
# you can change to another field
roles_field :roles_mask, :roles => [:admin, :manager, :teacher, :student]
end
then
@user.roles
# -> []
@user.role = :manager
@user.save
@user.roles
# -> [:manager]
@user.set_role :admin
@user.save
@user.roles
# -> [:admin]
@user.role? :admin
@user.is_admin?
# -> true
@user.role? :teacher
@user.is_teacher?
# -> false
@user.role
# -> :admin
# return user's first role
User.with_role :admin
# -> scope [...]
to support multi-roles setting