module ActiveAdmin::BatchActions::Controller

Constants

COLLECTION_APPLIES

Public Instance Methods

batch_action() click to toggle source

Controller action that is called when submitting the batch action form

# File lib/active_admin/batch_actions/controller.rb, line 7
def batch_action
  if action_present?
    selection = params[:collection_selection] || []
    inputs = JSON.parse params[:batch_action_inputs] || "{}"
    valid_keys = MethodOrProcHelper.render_in_context(self, current_batch_action.inputs).try(:keys)
    inputs = inputs.with_indifferent_access.slice *valid_keys
    instance_exec selection, inputs, &current_batch_action.block
  else
    raise "Couldn't find batch action \"#{params[:batch_action]}\""
  end
end

Protected Instance Methods

action_present?() click to toggle source
# File lib/active_admin/batch_actions/controller.rb, line 21
def action_present?
  params[:batch_action].present? && current_batch_action
end
batch_action_collection(only = COLLECTION_APPLIES) click to toggle source
# File lib/active_admin/batch_actions/controller.rb, line 36
def batch_action_collection(only = COLLECTION_APPLIES)
  find_collection(only: only)
end
current_batch_action() click to toggle source
# File lib/active_admin/batch_actions/controller.rb, line 25
def current_batch_action
  active_admin_config.batch_actions.detect { |action| action.sym.to_s == params[:batch_action] }
end