开发者

In cancan, how to check if can? manage each and every record for a given model

  1. My admin can :manage, Widget
  2. My user can :manage, Widget, :user_id => user.id
  3. In my view, I want to show a link only开发者_开发知识库 if the current_user can manage each and every Widget record.


In general?

can? :manage, Widget

If you're referring to some check on existing records, that sounds like a design flaw, but this should work. Note that if this is the approach you're taking, you have a race condition with other Widget records being created after you make this check.

(can? :manage, Widget) || (Widget.count == Widget.count(:conditions => ["user_id == ?", current_user.id]))

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜