【问题标题】:Activeadmin, page_action and cancan rulesActiveadmin、page_action 和 cancan 规则
【发布时间】:2013-05-22 16:40:07
【问题描述】:

如何管理对 custom_page 操作的访问?我有这个代码:

ActiveAdmin.register_page 'Import' do
  menu false

  content do
    panel t('views.import.title') do
      render 'form'
    end
  end

  page_action :parse, method: :post do
    @import = current_user.imports.new(params[:import])
    if @import.save
      @import.process
    end
  end

  page_action :check_status do
    imports = current_user.imports.finished.unreaded
    size = imports.size
    imports.update_all readed: true
    render json: {has_new_ended: size}
  end
end

现在,只有管理员才能访问此操作,因为他的规则看起来像

can :manage, :all

但我需要将此操作访问到其他角色。如果我为某个角色这样做,那就无济于事了。

can [:check_status, :parse], ActiveAdmin::Page, name: 'Import'

还有这个

can [:manage, :parse, :check_status], Import

【问题讨论】:

    标签: ruby-on-rails activeadmin cancan


    【解决方案1】:

    通过在ability.rb中使用以下代码,您应该能够在当前用户在自定义页面时获得当前用户的所有权限。

    can :read, ActiveAdmin::Page, name: "Dashboard", namespace_name: "admin"
    

    【讨论】:

      【解决方案2】:

      您必须授权这些操作。 查看更多:https://github.com/ryanb/cancan#2-check-abilities--authorization

      【讨论】:

        【解决方案3】:

        您需要使用您的操作名称和页面名称。

        can :parse, ActiveAdmin::Page, name: 'Import'
        can :check_status, ActiveAdmin::Page, name: 'Import'
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多