0.0
No commit activity in last 3 years
No release in over 3 years
A dead simple roles plugin for Rails.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Miracle Roles

A dead simple roles plugin for Rails.

Install

1 — Get the gem

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

2 — Add :roles column to model

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

3 — Include module and define roles

Include the Miracle::Roles in your model:

class User < ActiveRecord::Base
  include Miracle::Roles
  define_roles :admin, :supervisior, ...
  
  ...
end

Usage

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)

Bitdeli Badge