module ActionArgs::ActiveSupport::CallbackParameterizer

For Rails >= 5.1

Public Instance Methods

make_lambda() click to toggle source

Extending AS::Callbacks::Callback's `make_lambda` not just to call specified method but to call the method with method parameters taken from `params`. This would happen only when

  • the target object is_a ActionController object

  • the filter was not defined via lambda

# File lib/action_args/callbacks.rb, line 14
def make_lambda
  lambda do |target, value, &block|
    target, block, method, *arguments = expand(target, value, block)

    if (ActionController::Base === target) && (method != :instance_exec) && arguments.empty?
      target.strengthen_params! method
      arguments, keyword_arguments = target.extract_method_arguments_from_params method
      if keyword_arguments.any?
        target.send(method, *arguments, **keyword_arguments, &block)
      else
        target.send(method, *arguments, &block)
      end
    else
      target.send(method, *arguments, &block)
    end
  end
end