如何删除activeAdmin的删除选项?

在rails gem active admin我想从default_actions中删除删除选项,而我仍然需要编辑和显示操作,有没有办法做到这一点?

您将actions添加到每个Active Admin资源:

 ActiveAdmin.register Foobar do actions :all, :except => [:destroy] end 

在某些时候,我有这个问题,因为销毁方法,'删除'button并没有消失

 actions :all, except: [:destroy] controller do def destroy # => Because of this the 'Delete' button was still there @user = User.find_by_slug(params[:id]) super end end 

接受的答案抛出了一个exception,“错误的参数数量”,所以我这样做,以排除删除button(:销毁行动)

 ActiveAdmin.register YourModel do actions :index, :show, :new, :create, :update, :edit index do selectable_column id_column column :title column :email column :name actions end 

如果你想完全移除删除button,使用:actions:all,除了:[:destroy]

但是,如果删除button需要基于资源属性的条件(例如关联的数据或状态)。

在索引页面:index do …… …… action默认值:false do | row | 如果能? :读取,行text_node link_to“查看”,admin_resource_path(行),类:“view_link”结束,如果可以? :编辑,行text_node link_to“编辑”,admin_resource_path(行),类:“edit_link”结束,如果可以? :destroy,row text_node link_to I18n.t('active_admin.delete'),admin_resource_path(row),method :: delete,data:{confirm:I18n.t('active_admin.delete_confirmation')},class:“delete_link”if row.deletable? 末端

结束

现在复杂的部分,我不得不几次击倒我的头来控制它在显示页面:

config.remove_action_item(:destroy)#将删除销毁button

只有action_item :: show do

 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? 

结束

对不起,我可怕的格式。