Module: StrongerParameters::ControllerSupport::PermittedParameters::ClassMethods

Defined in:
lib/stronger_parameters/controller_support/permitted_parameters.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



35
36
37
# File 'lib/stronger_parameters/controller_support/permitted_parameters.rb', line 35

def self.extended(base)
  base.send :class_attribute, :log_unpermitted_parameters, instance_accessor: false
end

Instance Method Details

#log_invalid_parameters!Object



39
40
41
# File 'lib/stronger_parameters/controller_support/permitted_parameters.rb', line 39

def log_invalid_parameters!
  self.log_unpermitted_parameters = true
end

#permitted_parameters(action, permitted) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/stronger_parameters/controller_support/permitted_parameters.rb', line 43

def permitted_parameters(action, permitted)
  if permit_parameters[action] == :skip || permitted == :skip
    permit_parameters[action] = permitted
  else
    action_permitted = (permit_parameters[action] ||= {})
    action_permitted.deep_merge!(permitted)
  end
end

#permitted_parameters_for(action) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/stronger_parameters/controller_support/permitted_parameters.rb', line 52

def permitted_parameters_for(action)
  unless for_action = permit_parameters[action]
    # NOTE: there is no easy way to test this, so make sure to test with
    # a real rails controller if you make changes.
    message = "Action #{action} for #{self} does not have any permitted parameters"
    message += " (#{instance_method(action).source_location.join(":")})" if method_defined?(action)
    raise(KeyError, message)
  end
  return :skip if for_action == :skip

  # FYI: we should be able to call sugar on the result of deep_merge, but it breaks tests
  permit_parameters[:all].deep_merge(for_action).transform_values { |v| PermittedParameters.sugar(v) }
end