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
啊好吧,我注意到按鈕,但我真正想要的是資源旁邊的鏈接,w hich是member_action,如果我正確閱讀文檔...我用member_action更新了我的代碼,但它似乎沒有顯示任何內容,但是......任何指針?活動管理文檔對我來說不是那麼清楚 – snowflakekiller
@ Karuna-bdc,我已經更新了我的初始文章。 – Omnigazer
謝謝!這幫助我獲得解決方案!另一個問題,如果你不介意 - 文件頂部的member_action的目的是什麼?僅僅是爲了生成路線? – snowflakekiller