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