我在理解声明性授权和嵌套 if_attributes 的文档时遇到了一些困难。
楷模:
class Company < ActiveRecord::Base
has_many :users, :through => :division
end
class Division < ActiveRecord::Base
belongs_to :company
has_many :users
end
class User < ActiveRecord::Base
belongs_to :post
end
我的规则:
role :company_admin do
includes :company_admin
has_permission_on :companies, :to => [:index, :show, :edit, :update] do
if_attribute :id => is { user.division.company.id } # This is the problem....
end
在我的层次结构中,我定义了一个 company_admin 角色,应该允许编辑他自己的公司以及所有部门和用户。公司管理员上方还有一个角色,可以完全编辑和添加公司以及下面的所有角色。
我似乎挂断了上面列出的规则(我知道这是不正确的,它只是一个例子的填充物)。我需要确定当前用户只能编辑自己的公司,不能编辑其他公司。这似乎是一个嵌套的 if_attribute 但我似乎无法理解文档中嵌套 if_attributes 的示例。
提前感谢您的任何帮助!