Sha256: c41dbdb08f7c43d379b84b968ce4991d554a0627281a6189e1e29f92242a759b

Contents?: true

Size: 1.18 KB

Versions: 15

Compression:

Stored size: 1.18 KB

Contents

module ActiveAdmin
  module BatchActions
    module Controller

      # Controller action that is called when submitting the batch action form
      def batch_action
        if action_present?
          selection  =            params[:collection_selection] || []
          inputs     = JSON.parse params[:batch_action_inputs]  || '{}'
          valid_keys = StringSymbolOrProcSetting.new(current_batch_action.inputs).value(self).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

      def action_present?
        params[:batch_action].present? && current_batch_action
      end

      def current_batch_action
        active_admin_config.batch_actions.detect{ |action| action.sym.to_s == params[:batch_action] }
      end

      COLLECTION_APPLIES = [
        :authorization_scope,
        :filtering,
        :scoping,
        :includes,
      ].freeze

      def batch_action_collection(only = COLLECTION_APPLIES)
        find_collection(only: only)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
activeadmin-rb-1.6.0 lib/active_admin/batch_actions/controller.rb
activeadmin-rb-1.5.2 lib/active_admin/batch_actions/controller.rb
activeadmin-rb-1.5.1 lib/active_admin/batch_actions/controller.rb
activeadmin-rb-1.5.0 lib/active_admin/batch_actions/controller.rb
activeadmin_addons-1.7.1 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/batch_actions/controller.rb
activeadmin-rb-1.4.0 lib/active_admin/batch_actions/controller.rb
activeadmin_addons-1.7.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/batch_actions/controller.rb
activeadmin-1.4.2 lib/active_admin/batch_actions/controller.rb
activeadmin-1.4.1 lib/active_admin/batch_actions/controller.rb
activeadmin-1.4.0 lib/active_admin/batch_actions/controller.rb
activeadmin_addons-1.6.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/batch_actions/controller.rb
activeadmin_addons-1.5.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/batch_actions/controller.rb
activeadmin_addons-1.4.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/batch_actions/controller.rb
activeadmin_addons-1.3.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/batch_actions/controller.rb
activeadmin_addons-1.2.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/batch_actions/controller.rb