开发者

CanCan complex ability definition

I have a Task object.

Tasks belong to a user OR a company.

A user can belong to many companies through employmentships (like a regional manager).

Is there a way that 开发者_如何转开发I can do a check with cancan to see if a task either belongs to the user or one of the companies they belong to?

i.e.

can :manage, Task, do |task|
   task.user_id == user.id || user.companies.each do |company|
     task.company_id == company.id
   end
end


Yes you can, If I understood this well, something like this should work:

can :manage, Task, do |task|
   task.user_id == user.id || user.company_ids.include?(task.company_id)
end

Best!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜