Module: ActionArgs::AbstractControllerClassMethods

Defined in:
lib/action_args/abstract_controller.rb

Instance Method Summary collapse

Instance 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


29
30
31
32
33
34
35
# File 'lib/action_args/abstract_controller.rb', line 29

def permits(*attributes)
  if attributes.last.is_a?(Hash) && attributes.last.extractable_options? && attributes.last.key?(:model_name)
    options = attributes.pop
    @permitting_model_name = options[:model_name]
  end
  @permitted_attributes = attributes
end