如何使用activeadmin删除管理员的“删除”选项?

时间:2019-03-31 18:14:41

标签: ruby-on-rails activeadmin

我试图了解为什么我无法使用活动管理员为管理员删除“删除”选项。

过去,我尝试删除管理按钮,但是一旦服务器运行,就不会进行任何更改。

我添加了以下行,这摆脱了1个删除按钮。但是,有2个需要删除。

使用删除按钮的示例:https://www.rubydoc.info/gems/active_admin_sidebar/0.0.4

  config.remove_action_item(:destroy)

研究并找到此代码后,这也无法正常工作。

link_to I18n.t('active_admin.delete'), admin_resource_path(resource), method: :delete, data: { confirm: I18n.t('active_admin.delete_confirmation') }, class: "delete_link" if resource.deletable?
ActiveAdmin.register AdminUser do
  config.remove_action_item(:destroy)

  permit_params :email, :password, :password_confirmation


  index do
    selectable_column
    id_column
    column :email
    column :current_sign_in_at
    column :sign_in_count
    column :created_at
    actions
  end

  filter :email
  filter :current_sign_in_at
  filter :sign_in_count
  filter :created_at

  form do |f|
    f.inputs do
      f.input :email
      f.input :password
      f.input :password_confirmation
    end
    f.actions
  end

end
`````````````````````````````````````````````````````````````````````````````

1 个答案:

答案 0 :(得分:0)

如果要跳过按钮中的“破坏”操作,则有两种方法:

  1. 传递允许的操作列表:
index do
  selectable_column
  id_column
  # ... other columns
  actions :index, :show, :new, :create, :update, :edit
end
  1. 使用except键的actions方法传递不允许的操作:
index do
  selectable_column
  id_column
  # ... other columns
  actions :all, except: :destroy
end

或者您可以为资源的每个页面禁用:destroy操作:

ActiveAdmin.register AdminUser do
  actions :all, :except => :destroy
end

或者您可以清除资源的所有操作:

ActiveAdmin.register AdminUser do
  config.clear_action_items!

  # After this you can go ahead and define custom 
  # action items as you please
end

来源:

  1. https://activeadmin.info/2-resource-customization.html

  2. https://github.com/activeadmin/activeadmin/issues/341

  3. https://github.com/activeadmin/activeadmin/issues/760