A dead simple roles plugin for Rails.
Add the dependency to your config/environent.rb:
Rails::Initializer.run do |config|
...
config.gem "miracle_roles"
...
end
Now install it
sudo rake gems:install
Generate a migration to add column to your model (Users, in this example):
script/generate migration add_roles_to_users
Then in the migration that's generated, define the following:
class AddRolesToUsers < ActiveRecord::Migration
def self.up
add_column :users, :roles, :string
end
def self.down
remove_column :users, :roles
end
end
Include the Miracle::Roles in your model:
class User < ActiveRecord::Base
include Miracle::Roles
define_roles :admin, :supervisior, ...
...
end
Now you can manage roles in any of the following ways:
@user.add_role(:admin)
@user.remove_role(:admin)
@user.roles = [:admin, :supervisor]
Enjoy!
~ Mark Dodwell (@madeofcode)