2016-03-01 55 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