在我的数据模型中:
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。
类似于这个psuedocode:
Employee can :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谢谢!
发布于 2014-12-13 22:17:54
can :edit, Appointment, office_id: employee.office_idshttps://stackoverflow.com/questions/27461875
复制相似问题