0
나는 위의 블록 만 가게의 인스턴스가 아닌 클래스에서 실행 얻을해야한다고 생각하기 때문에 staff.can? :manage
여기에 true를 돌려 왜 나는 확실하지 않다블록이있는 CanCan이 클래스에 권한을 부여합니까?
def initialize(staff)
staff ||= Staff.new
can :manage, Store do |store|
store.staff_privileges.select(&:owner?).map(&:staff_id).include? staff.id
end
end
내 능력 클래스에서 다음과 같습니다 뭔가를 https://github.com/ryanb/cancan/wiki/Defining-Abilities-with-Blocks
The block is only evaluated when an actual instance object is present. It is not evaluated when checking permissions on the class (such as in the index action). This means any conditions which are not dependent on the object attributes should be moved outside of the block.
에서 자체
staff = Staff.first
staff.can? :manage, Store #true
staff.can? :manage, Store.first #false, because there is no staff_privileges associated to this store