2014-12-04 5 views
1

내 응용 프로그램에서 cancancan 및 activeadmin gem을 사용하고 있습니다. 사용자 정의 작업이 작동하지 않습니다.cancancan 사용자 정의 작업이 작동하지 않습니다.

if ((user.has_role? :HRMS_Supervisor) && (user.has_application? :HRMS)) 
     can :manage, User 
     can :approve, User // custom action 
    end 

    if ((user.has_role? :HRMS_Employee) && (user.has_application? :HRMS)) 
     can :read, Employee 
     can :manage, User 
     can :employee_access, User // custom action 
    end 

내 ActiveAdmin을 파일

ActiveAdmin.register Teleworker do 
    scope :pending, default: true 
    scope :approved 
    scope :rejected, if: proc{ can? :employee_access, current_user } 
    scope :all 

index do 
    selectable_column 
    column "Action" do |resource| 
    links = ''.html_safe 
    if can? :approve, current_user 
    links += link_to "approve", resource_path(resource), class: "member_link view_link" 
    end 
    end 
end 

거부 ​​된 범위와 LINK_TO ability.rb "승인"모두 역할에 표시됩니다. 이 문제를 해결하는 방법.

답변

1

can :manage, User에는 이미 모든 맞춤 동작이 포함되어 있습니다. 따라서 두 가지 역할 모두 사용자 지정 작업을 모두 수행 할 수 있습니다.

두 가지 역할 모두에 대해 can %i(create read update delete), User 대신 can :manage, User을 사용할 수 있습니다.

+0

... 또한 맞춤 동작을 승인해야합니다. https://github.com/CanCanCommunity/cancancan/wiki/Authorizing-controller-actions – nistvan

+0

감사합니다. –