Permissive rails gem的替代品?

时间:2011-11-15 23:57:21

标签: ruby-on-rails gem

任何人都知道Permissive的替代品吗?还是在功能方面进行比较的其他宝石?

2 个答案:

答案 0 :(得分:1)

我不知道它是否符合'基于模型'的标准,但您看过CanCan吗?:

https://github.com/ryanb/cancan

编辑:

Cancan已经停产(非正式),贡献者创建了一个名为Cancancan的新项目。

https://github.com/bryanrite/cancancan

答案 1 :(得分:1)

我更喜欢 declarative_authorization 而不是cancan,如果用户的角色更复杂

https://github.com/stffn/declarative_authorization

http://railscasts.com/episodes/188-declarative-authorization

http://steffenbartsch.com/blog/2008/09/delclarative-authorization/


使用declarative_authorization,您可以定义模型和方法的基于角色的授权。

您可以定义模型的权限以及模型中的方法。如果满足某些条件,您可以进一步限制权限,例如:您可以指定仅当对象的某个属性具有特定值时才应用某些权限。

这是一个例子,它指明普通用户只能读取和修改他/她被雇用的公司的帐户(假设帐户以树状方式排列,例如“祖先”宝石)

authorization do 
 role :user do
    # ...
    has_permission_on :accounts , :to => [:index, :show, :edit, :update] do
      if_attribute :id => is_in { user.employed_at_account.subtree_ids }
    end
    # ...
  end

  role :admin do
    # ...
    has_permission_on :accounts , :to => [:create, :new, :index, :show , :edit, :update  ]
    # ...
  end   
end