CanCan custom actions not working with blocks

I am modifying some of my CanCan user actions in the Ability class to use blocks instead of a hash, but now they have stopped actually restricting access. It is strange that the built-in actions, such as: manage and: create, etc., seem to still work fine with 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

Has anyone encountered this problem before?

+5
source share
1 answer

I can't say much about your unwanted behavior, but you probably shouldn't change the hashes to block, as these hashes give you the ability to receive entries. Read this article on the CanCan wiki.

+1

All Articles