Mani David
Mani David

Reputation: 1412

cancancan custom action not working

Am using cancancan and activeadmin gems in my application, in cancan gem the custom action is not working.

ability.rb

 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

my activeadmin file

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

the rejected scope and link_to "approve" is displaying for both the roles. how to solve this.

Upvotes: 2

Views: 3174

Answers (1)

mikdiet
mikdiet

Reputation: 10038

can :manage, User already includes all custom actions. So, both your roles can perform both custom actions.

You can use the list of crud actions: can %i(create read update delete), User instead can :manage, User for both roles.

Upvotes: 2

Related Questions