Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Share Ability Definitions

ryanb edited this page Oct 6, 2010 · 2 revisions

Let's say the ability of one action depends on the ability of another. For example, what if we have a Project which has_many :tasks and we want a task's update ability to be dependent on whether the user can update the project. We can perform the can? call within the ability definition to check the project permission.

can :update, Task do |task|
  can?(:update, task.project)
end

With this it is easy to define one ability based on another.