class ActiveAdmin::BatchAction
def <=>(other)
def <=>(other) self.priority <=> other.priority end
def confirm
def confirm if @confirm == true DEFAULT_CONFIRM_MESSAGE elsif !@confirm && @options[:form] DEFAULT_CONFIRM_MESSAGE else @confirm end end
def display_if_block
Returns the display if block. If the block was not explicitly defined
def display_if_block @options[:if] || proc{ true } end
def initialize(sym, title, options = {}, &block)
=> You can pass a hash of options to `:form` that will be rendered as form input fields for the user to fill out.
BatchAction.new(:flag, form: {foo: :text, bar: :checkbox}) { |selection, inputs| }
=> You can pass a custom confirmation message through `:confirm`
BatchAction.new(:flag, confirm: "Are you sure?") { |selection| }
=> You can pass `true` to `:confirm` to use the default confirm message.
BatchAction.new :flag, confirm: true
=> You can provide an `:if` proc to choose when the batch action should be displayed
BatchAction.new(:flag, if: proc{ can? :flag, AdminUser }) { |selection| }
=> You can create batch actions with a title instead of a Symbol
BatchAction.new("Perform Long Operation on") { |selection| }
=> Will create an action that uses a block to process the request (which receives one paramater of the selected objects)
BatchAction.new(:flag) { |selection| redirect_to collection_path, notice: "#{selection.length} users flagged" }
=> Will create an action that appears in the action list popover
BatchAction.new :flag
Examples:
Create a Batch Action
def initialize(sym, title, options = {}, &block) @sym, @title, @options, @block, @confirm = sym, title, options, block, options[:confirm] @block ||= proc {} end
def inputs
def inputs @options[:form] end
def priority
def priority @options[:priority] || 10 end