开发者

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

开发者 https://www.devze.com 2023-03-30 00:35 出处:网络
My admin can :manage, Widget My user can :manage, Widget, :user_id => user.id In my view, I want to show a link only开发者_开发知识库 if the current_user can manage each and every Widget record.
  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

精彩评论

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