2016-03-01 80 views
2

I am following active_admin's documentation on action items試圖向我的管理視圖添加「批准」操作。活動管理操作項不顯示

我有我的activeadmin寄存器設置是這樣的:

ActiveAdmin.register PendingClaim do 


    action_item :approve, method: :post, only: [:show, :index] do 
    link_to('Approve', "#") 
    end 


    index do 
    column "Business ID", :business_id 
    column "User ID", :user_id 
    column "Claim approved by Admin?", :approved 
    column :created_at 
    end 



    controller do 
    # This code is evaluated within the controller class 

    def approve 
     binding.pry 
    end 
    end 
end 

,但它並不顯示在表中批准的行動。我希望批准操作映射到PendingClaim控制器中的#approve操作。不知道我在這裏做...

我也試圖加入行動,我的指數,像這樣:

index do 
    column "Business ID", :business_id 
    column "User ID", :user_id 
    column "Claim approved by Admin?", :approved 
    column :created_at 
    actions 
    end 

但只是沒有表現出我的自定義默認行爲批准行動

編輯 -

基於@ Omnigazer的回答,我改變了我的代碼

ActiveAdmin.register PendingClaim do 


    member_action :approve, only: :index do 
    redirect_to resource_path, notice: "Approved!" 
    end 


    index do 
    column "Business ID", :business_id 
    column "User ID", :user_id 
    column "Claim approved by Admin?", :approved 
    column :created_at 
    end 



    controller do 
    # This code is evaluated within the controller class 

    def approve 
     binding.pry 
    end 
    end 
end 

但仍然不顯示動作。

編輯 -

感謝Omnigazer,我設法得到它的工作,我的代碼:

ActiveAdmin.register PendingClaim do 
    member_action :approve, method: :post, only: :index do 
    end 

    index do 
    column :created_at 
    column 'Business ID', :business_id 
    column 'User ID', :user_id 
    column 'Claim approved by Admin?', :approved 
    actions defaults: false do |pending_claim| 
     params = { business_id: pending_claim.business_id, 
       user_id: pending_claim.user_id } 
     link_to('Approve', approve_admin_pending_claim_path(pending_claim, params), method: :post) 
    end 
    end 

    controller do 
    # This code is evaluated within the controller class 

    def approve 
     business = Business.find(params[:business_id]) 
     user = Business.find(params[:user_id]) 
     business.user_id = user.id 
     business.verified = true 
     if business.save 
     resource.approved = true 
     resource.save 
     redirect_to resource_path(resource), notice: 'Claim Approved!' 
     end 
    end 
    end 
end 

回答

2

的行動項出現在頁面上,在「創造的右上角%{model_name%}「」按鈕通常駐留。嘗試在那裏尋找它。否則,你的代碼看起來有效。雖然ActiveAdmin對於像您這樣的案例,擁有自己的DSL方法「collection_action」和「member_action」。嘗試在文檔中查找它們。

編輯: 如果你想旁邊的默認行爲追加的行動項目,試試這個:

index do 
    ... 
    actions defaults: true do |order| 
    link_to('Approve', "#") 
    end 
end 
+0

啊好吧,我注意到按鈕,但我真正想要的是資源旁邊的鏈接,w hich是member_action,如果我正確閱讀文檔...我用member_action更新了我的代碼,但它似乎沒有顯示任何內容,但是......任何指針?活動管理文檔對我來說不是那麼清楚 – snowflakekiller

+0

@ Karuna-bdc,我已經更新了我的初始文章。 – Omnigazer

+0

謝謝!這幫助我獲得解決方案!另一個問題,如果你不介意 - 文件頂部的member_action的目的是什麼?僅僅是爲了生成路線? – snowflakekiller

0
#action_item(name = nil, options = {}, &block) ⇒ Object 

添加一個新的動作項資源

參數: (默認爲 爲:{}) - 有效密鑰包括::only:單個控制器或數組控制器 顯示此操作的操作時間。 :除了:單個或數組 控制器操作不到

顯示此操作項目。

action_item documentaion

我覺得沒有期權method:選項有

主動管理文檔具有很好的例子,如何使用它

page_action :add_event, method: :post do 
    # ... 
    redirect_to admin_calendar_path, notice: "Your event was added" 
end 

action_item :add do 
    link_to "Add Event", admin_calendar_add_event_path, method: :post 
end 

source