2011-10-12 104 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? 

對不起,我可怕的格式。