Exception: ActionController::ParameterMissing

Inherits:
KeyError
  • Object
show all
Includes:
DidYouMean::Correctable
Defined in:
actionpack/lib/action_controller/metal/strong_parameters.rb

Overview

Raised when a required parameter is missing.

params = ActionController::Parameters.new(a: {})
params.fetch(:b)
# => ActionController::ParameterMissing: param is missing or the value is empty: b
params.require(:a)
# => ActionController::ParameterMissing: param is missing or the value is empty: a

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(param, keys = nil) ⇒ ParameterMissing

:nodoc:


24
25
26
27
28
# File 'actionpack/lib/action_controller/metal/strong_parameters.rb', line 24

def initialize(param, keys = nil) # :nodoc:
  @param = param
  @keys  = keys
  super("param is missing or the value is empty: #{param}")
end

Instance Attribute Details

#keysObject (readonly)

:nodoc:


22
23
24
# File 'actionpack/lib/action_controller/metal/strong_parameters.rb', line 22

def keys
  @keys
end

#paramObject (readonly)

:nodoc:


22
23
24
# File 'actionpack/lib/action_controller/metal/strong_parameters.rb', line 22

def param
  @param
end

Instance Method Details

#correctionsObject

:nodoc:


33
34
35
# File 'actionpack/lib/action_controller/metal/strong_parameters.rb', line 33

def corrections # :nodoc:
  @corrections ||= DidYouMean::SpellChecker.new(dictionary: keys).correct(param.to_s)
end