Sha256: 96e0da1a84c6b47ac0fa245db8977e7a4900d62472f25b51bf51ff8ad66d31ac

Contents?: true

Size: 1.65 KB

Versions: 7

Compression:

Stored size: 1.65 KB

Contents

module AbstractController
  class Base
    if defined? ActionController::StrongParameters
      def send_action(method_name, *args)
        return send method_name, *args unless args.empty?
        return send method_name, *args unless defined?(params)

        method_parameters = method(method_name).parameters
        ActionArgs::ParamsHandler.strengthen_params!(self.class, method_parameters, params)
        values = ActionArgs::ParamsHandler.extract_method_arguments_from_params method_parameters, params
        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)
        if attributes.last.is_a?(Hash) && attributes.last.extractable_options? && attributes.last.has_key?(:model_name)
          options = attributes.pop
          @permitting_model_name = options[:model_name]
        end
        @permitted_attributes = attributes
      end
    # no StrongParameters
    else
      def send_action(method_name, *args)
        return send method_name, *args unless args.empty?
        return send method_name, *args unless defined?(params)

        values = ActionArgs::ParamsHandler.extract_method_arguments_from_params method(method_name).parameters, params
        send method_name, *values
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
action_args-1.5.4 lib/action_args/abstract_controller.rb
action_args-1.5.3 lib/action_args/abstract_controller.rb
action_args-1.5.2 lib/action_args/abstract_controller.rb
action_args-1.5.1 lib/action_args/abstract_controller.rb
action_args-1.4.0 lib/action_args/abstract_controller.rb
action_args-1.3.0 lib/action_args/abstract_controller.rb
action_args-1.2.1 lib/action_args/abstract_controller.rb