【发布时间】:2014-12-13 17:52:47
【问题描述】:
在我的数据模型中:
Company has_many offices
Employee has_many offices, through: :employee_office(这就是我允许公司管理员允许员工进入某些办公室而不是其他办公室的方式)
Office has_many appointments 和
Appointment belongs_to office
我想使用CanCanCan 定义一个功能,它允许Employee 对Appointment 执行操作,前提是Employee 在Office 上工作,Appointment 是在Appointment 上创建的。
类似这样的伪代码:
Employeecan :manage Appointment, Employee.offices.include?(Appointment.office)
这是我目前所拥有的:
class EmployeeAbility
include CanCan::Ability
def initialize(employee)
can :read, Company, :id => employee.company.id
can :read, Office, :id => employee.company.id
#I'd like to include the above psuedocode here, but I'm not sure how to structure it
end
end
谢谢!
【问题讨论】:
标签: ruby-on-rails ruby authorization cancan cancancan