2015-04-02 99 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