Class: AbstractController::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/action_args/abstract_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.permits(*attributes) ⇒ Object

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


25
26
27
28
29
30
31
# File 'lib/action_args/abstract_controller.rb', line 25

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

Instance Method Details

#send_action(method_name, *args) ⇒ Object



6
7
8
9
10
11
# File 'lib/action_args/abstract_controller.rb', line 6

def send_action(method_name, *args)
  return send method_name, *args unless args.empty?
  return send method_name, *args unless defined?(params)

  send_with_method_parameters_from_params method_name
end