【问题标题】:cancancan custom action not workingcancancan 自定义操作不起作用
【发布时间】:2014-12-04 08:35:34
【问题描述】:

我在我的应用程序中使用 cancancan 和 activeadmin gem,在 cancan gem 中自定义操作不起作用。

能力.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.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

拒绝的范围和链接到“批准”显示为两个角色。如何解决这个问题。

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多