Plugin git repo : https://github.com/platform45/easy_roles
Step 1 : Install Plugin
Step 2 : Generate migration to create column called roles in user's table
script/plugin install git://github.com/platform45/easy_roles.git
Step 2 : Generate migration to create column called roles in user's table
rails g easy_roles user roles
Step 3 : Run. rake db:migrate to run the migration
Step 4 : Add this line to the user's model
class User < ActiveRecord::Base
easy_roles :roles
end
@user = User.first
@user.add_role 'admin'
@user.is_admin?
=> true
@user.has_role? 'admin'
=> true
@user.is_awesome?
=> false
@user.add_role 'awesome'
@user.is_awesome?
=> true
@user.remove_role 'admin'
@user.is_admin?
=> false
No comments:
Post a Comment