2011-10-12 152 views

回答

86

您调用actions添加到每个主动管理资源:

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

在某些时候,我有这个问题,因为破坏的方法,“删除”按钮并没有消失

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 
0

接受的答案抛出异常,“错误的参数数目”,所以我这样做是为了排除删除按钮(:破坏行动)

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 
0

如果要删除删除按钮完全使用: 操作:除:[:destroy]

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

在索引页: 指数做 ...... ...... 行动的默认值:假做|行| 如果可以? :第 text_node link_to“查看”,admin_resource_path(row) :编辑,行 text_node link_to“编辑”,admin_resource_path(row),class:“edit_link” end if can? :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”如果row.deletable? 结束 结束

现在复杂的部分,我不得不一声我的头几次在节目页面来控制它:

config.remove_action_item(:销毁)#将删除销毁按钮

action_item只:节目做

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? 

对不起,我可怕的格式。