module AbstractController
  class Base
    def send_action(method_name, *args)
      return send method_name, *args unless args.blank?

      values = if defined? ActionController::StrongParameters
        target_model_name = self.class.name.sub(/Controller$/, '').singularize.underscore.to_sym
        permitted_attributes = self.class.instance_variable_get '@permitted_attributes'
        method(method_name).parameters.map {|type, key|
          next if type == :block
          params.require key if type == :req
          if (key == target_model_name) && permitted_attributes
            params[key].try :permit, *permitted_attributes
          else
            params[key]
          end
        }.compact
      else
        method(method_name).parameters.map {|type, key| params[key] unless type == :block }.compact
      end
      send method_name, *values
    end

    # You can configure StrongParameters' `permit` attributes using this DSL method.
    # The `permit` call will be invoked only against parameters having the resource
    # model name inferred from the controller class name.
    #
    #   class UsersController < ApplicationController
    #     permits :name, :age
    #
    #     def create(user)
    #       @user = User.new(user)
    #     end
    #   end
    #
    def self.permits(*attributes)
      @permitted_attributes = attributes
    end
  end
end

module AbstractController
  class Base
    def send_action(method_name, *args)
      return send method_name, *args unless args.blank?

      values = if defined? ActionController::StrongParameters
        target_model_name = self.class.name.sub(/Controller$/, '').singularize.underscore.to_sym
        permitted_attributes = self.class.instance_variable_get '@permitted_attributes'
        method(method_name).parameters.reject {|type, _| type == :block }.map {|type, key|
          params.require key if type == :req
          if (key == target_model_name) && permitted_attributes
            params[key].try :permit, *permitted_attributes
          else
            params[key]
          end
        end
      else
        method(method_name).parameters.reject {|type, _| type == :block }.map(&:last).map {|key| params[key]}
      end
      send method_name, *values
    end

    # You can configure StrongParameters' `permit` attributes using this DSL method.
    # The `permit` call will be invoked only against parameters having the resource
    # model name inferred from the controller class name.
    #
    #   class UsersController < ApplicationController
    #     permits :name, :age
    #
    #     def create(user)
    #       @user = User.new(user)
    #     end
    #   end
    #
    def self.permits(*attributes)
      @permitted_attributes = attributes
    end
  end
end

Revert "reduce number of objects"
Revert "reduce number of objects"

This reverts commit 59d71b6e525274c861bfcbd0142f7753473f4d4a.

Conflicts:
	lib/action_args/abstract_controller.rb

reason: compacting all parameters will eliminate nil parameters
