2012-11-13 2 views
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 

답변

0

는 왜 이런 일이 있을까? 나도 몰라,하지만 그 대답은 "인덱스 작업과 같은"비트라고 생각합니다. 이 동작이 없으면 load_and_authorize_resource 메소드가 인덱스 조치에 대해 작동하지 않을 수 있습니다.

관련 문제