Method: ActiveAdmin::BatchAction#initialize
- Defined in:
- lib/active_admin/batch_actions/resource_extension.rb
#initialize(sym, title, options = {}, &block) ⇒ BatchAction
Create a Batch Action
Examples:
BatchAction.new :flag
> Will create an action that appears in the action list popover
BatchAction.new(:flag) { |selection| redirect_to collection_path, notice: "#{selection.length} users flagged" }
> Will create an action that uses a block to process the request (which receives one paramater of the selected objects)
BatchAction.new("Perform Long Operation on") { |selection| }
> You can create batch actions with a title instead of a Symbol
BatchAction.new(:flag, if: proc{ can? :flag, AdminUser }) { |selection| }
> You can provide an :if proc to choose when the batch action should be displayed
BatchAction.new :flag, confirm: true
> You can pass true to :confirm to use the default confirm message.
BatchAction.new(:flag, confirm: "Are you sure?") { |selection| }
> You can pass a custom confirmation message through :confirm
BatchAction.new(:flag, form: {foo: :text, bar: :checkbox}) { |selection, inputs| }
> You can pass a hash of options to :form that will be rendered as form input fields for the user to fill out.
116 117 118 119 120 121 122 123 |
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 116 def initialize(sym, title, = {}, &block) @sym = sym @title = title @options = @block = block @confirm = [:confirm] @block ||= proc {} end |