Module: ActiveAdmin::BatchActions::ResourceExtension

Defined in:
lib/active_admin/batch_actions/resource_extension.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) add_batch_action(sym, title, options = {}, &block)

Add a new batch item to a resource

> :if is a proc that will be called to determine if the BatchAction should be displayed

> :sort_order is used to sort the batch actions ascending

> :confirm is a string to prompt the user with (or a boolean to use the default message)

> :form is a Hash of form fields you want the user to fill out

Parameters:

  • title (String)
  • options (Hash) (defaults to: {})


37
38
39
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 37

def add_batch_action(sym, title, options = {}, &block)
  @batch_actions[sym] = ActiveAdmin::BatchAction.new(sym, title, options, &block)
end

- (Object) batch_action_path(params = {})

Path to the batch action itself



55
56
57
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 55

def batch_action_path(params = {})
  [route_collection_path(params), "batch_action"].join("/")
end

- (Array) batch_actions

Returns The set of batch actions for this resource

Returns:

  • (Array)

    The set of batch actions for this resource



12
13
14
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 12

def batch_actions
  batch_actions_enabled? ? @batch_actions.values.sort : []
end

- (Object) batch_actions=(bool)

Disable or Enable batch actions for this resource Set to `nil` to inherit the setting from the namespace



25
26
27
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 25

def batch_actions=(bool)
  @batch_actions_enabled = bool
end

- (Boolean) batch_actions_enabled?

Returns If batch actions are enabled for this resource

Returns:

  • (Boolean)

    If batch actions are enabled for this resource



17
18
19
20
21
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 17

def batch_actions_enabled?
  # If the resource config has been set, use it. Otherwise
  # return the namespace setting
  @batch_actions_enabled.nil? ? namespace.batch_actions : @batch_actions_enabled
end

- (Object) clear_batch_actions!

Clears all the existing batch actions for this resource



50
51
52
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 50

def clear_batch_actions!
  @batch_actions = {}
end

- (Object) initialize



5
6
7
8
9
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 5

def initialize(*)
  super
  @batch_actions = {}
  add_default_batch_action
end

- (Object) remove_batch_action(sym)

Remove a batch action

Parameters:

  • sym (Symbol)


45
46
47
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 45

def remove_batch_action(sym)
  @batch_actions.delete(sym.to_sym)
end