cancancan自定义动作不起作用

时间:2014-12-04 08:35:35

标签: ruby-on-rails activeadmin ruby-on-rails-4.1 cancancan

在我的应用程序中使用cancancan和activeadmin gems,在cancan gem中自定义操作无法正常工作。

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

我的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"批准"正在显示两个角色。如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

can :manage, User已包含所有自定义操作。因此,您的两个角色都可以执行自定义操作。

您可以对两个角色使用crud操作列表:can %i(create read update delete), User而不是can :manage, User

相关问题