简体   繁体   English

cancan 没有调用能力方法

[英]cancan is not calling the ability method

I want to limit the access to read the lead for a user.我想限制读取用户潜在客户的访问权限。 I have the relation as: Account has many office and Account also has users.我的关系为:帐户有很多办公室,帐户也有用户。 And Office has leads. Office 有线索。 Now only the user associated with the office can view its lead.现在只有与办公室关联的用户才能查看其潜在客户。

I have defined the ability as:我将能力定义为:

 can :read, Lead do |lead, office|
      @office && user.account_ids.include?(@office.account_id)
 end

And I have this in the view:我认为:

- if can? :read, Lead, @office

but I can see that the above ability check is not being called with the view mentioned.但我可以看到上面提到的视图没有调用上述能力检查。 Am I messing something here?我在这里搞砸什么吗?

The code should read something like this:代码应该是这样的:

can :read, Office do |office|
  office && user.account_ids.include?(office.account_id)
end

View:看法:

- if can? :read, @office

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM