2015-04-02 104 views
1

是否有任何方式为批处理操作添加可自定义的参数?Activeadmin - 带参数的批量操作?

例如,我有这个批处理动作:

batch_action :add_points do |ids| 
    User.find(ids).each do |user| 
    user.add_points "Some description", 10 
    end 
end 

我需要的参数通过弹出窗口或别人add_points定制。

+1

https://github.com/activeadmin/activeadmin/blob/6bde1f57ec5f9b724c21e5af146678f4ade839bc/lib/active_admin/batch_actions/views/batch_action_popover.rb – karlingen 2015-04-02 06:59:44

回答

3

实测值的正式文档中的溶液:

batch_action :add_points, form: {desc: :text, amount: :text} do |ids, inputs| 
    User.find(ids).each do |user| 
    user.add_points inputs['desc'], inputs['amount'].to_i 
    end 
end