Rails 易于管理角色
= Easy Roles
Simple rails gem for basic role authorization with ruby on rails.
== Changelog
Please read the CHANGELOG.rdoc file.
== Install
gem install easy_roles
or it can be installed as a rails plugin.
script/plugin install git://github.com/platform45/easy_roles.git
== Basic Setup
=== Serialize Method
Add the following to your Gemfile: gem 'easy_roles'
Then generate the migration: rails g easy_roles user roles
Or add a "roles" column to your users model, and set the default value to "--- []". Please note you can call this column anything you like, I like to use the name "roles".
t.string :roles, default: "--- []"
Then you need to add "easy_roles :column_name" to your model:
class User 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
etc etc
== Protecting controllers
There are many ways to implement views for specific roles, so I did not specifically supply one. Here's an example on what you could do:
class ApplicationController SELECT "bitmask_users".* FROM "bitmask_users" WHERE "bitmask_users"."roles_mask" IN (1, 3, 5, 7) AND "bitmask_users"."active" = 't'
SerializeUser.with_role('admin').where(active: true).to_sql
Follow me on twitter: http://twitter.com/ryan_za
Email: ryan at platform45.com
== License
Copyright (c) 2011 Platform45
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
暂无开放 Issues,或尚未同步最近议题。