开发者

CanCan custom actions not working with blocks

开发者 https://www.devze.com 2023-02-05 21:19 出处:网络
I\'m changing some of my custom CanCan actions in the Ability class to use blocks instead of just a hash but now they\'ve stopped actually restricting access. The odd thing is that the built in action

I'm changing some of my custom CanCan actions in the Ability class to use blocks instead of just a hash but now they've stopped actually restricting access. The odd thing is that the built in actions like :manage and :create, etc. seem to still be working fine with the blocks.

This is one example:

OLD

# this one works
can :share, Project, 开发者_开发百科:user_id => user.id

NEW

# this one doesn't work
can :share, Project do |project|
  project.users.exists?(user)
end

Anyone run into this issue before?


I can't say much about your undesired behavior, but you probably shouldn't be changing hashes to block, as these hashes give you the ability of fetching records. Read this article carefully in CanCan wiki.

0

精彩评论

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

关注公众号