【发布时间】:2015-12-14 12:50:39
【问题描述】:
我有两个模型 Organization 和 Users 我正在使用 Rolify 进行连接。
用户有角色,组织是一种资源。
这很好用,但是我的问题是尝试获取特定资源的用户列表。我想获取在该资源上具有任何角色的所有用户的列表(而且我不关心通用管理员等类级别的角色)
我尝试做类似下面的事情,但它很糟糕,它仍然返回一个类级别管理员的列表(那些有管理员但实际上不在任何特定资源上的人)。
class Organization < ActiveRecord::Base
resourcify
def users
# this is terrible and still doesn't work right.
User.with_role(:admin, self) + User.with_role(:press, self)
end
end
class User < ActiveRecord::Base
rolify
def organizations
Organization.with_roles(Role.role_names, self).uniq
end
end
有什么想法吗?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 cancan cancancan rolify