Sha256: c485bf41593d71dcd25611ca73cf1cccd58520f8c56b249b0e6833bc3e6b03f8

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
action_args-1.0.1 lib/action_args/abstract_controller.rb