diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2013-11-02 15:40:39 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2013-11-02 15:40:39 -0700 |
commit | 6d30219c2734f2678d74a54b791a311748b3e64f (patch) | |
tree | b9da7bebd2e3c375afab44791fd4205254f13b50 /actionpack/lib/action_controller/metal/strong_parameters.rb | |
parent | 423249504a2b468d7a273cbe6accf4f21cb0e643 (diff) | |
parent | a2f27385f60292c77e5e29a9568f1888a7c3d214 (diff) | |
download | rails-6d30219c2734f2678d74a54b791a311748b3e64f.tar.gz rails-6d30219c2734f2678d74a54b791a311748b3e64f.tar.bz2 rails-6d30219c2734f2678d74a54b791a311748b3e64f.zip |
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'actionpack/lib/action_controller/metal/strong_parameters.rb')
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 8ae7e474a3..b4948d99a8 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -10,26 +10,14 @@ module ActionController # params = ActionController::Parameters.new(a: {}) # params.fetch(:b) # # => ActionController::ParameterMissing: param not found: b + # params.require(:a) + # # => ActionController::ParameterMissing: param not found: a class ParameterMissing < KeyError attr_reader :param # :nodoc: def initialize(param) # :nodoc: @param = param - super("param not found: #{param}") - end - end - - # Raised when a required parameter value is empty. - # - # params = ActionController::Parameters.new(a: {}) - # params.require(:a) - # # => ActionController::EmptyParameter: value is empty for required key: a - class EmptyParameter < IndexError - attr_reader :param - - def initialize(param) - @param = param - super("value is empty for required key: #{param}") + super("param is missing or the value is empty: #{param}") end end @@ -169,22 +157,20 @@ module ActionController self end - # Ensures that a parameter is present. If it's present and not empty, - # returns the parameter at the given +key+, if it's empty raises - # an <tt>ActionController::EmptyParameter</tt> error, otherwise - # raises an <tt>ActionController::ParameterMissing</tt> error. + # Ensures that a parameter is present. If it's present, returns + # the parameter at the given +key+, otherwise raises an + # <tt>ActionController::ParameterMissing</tt> error. # # ActionController::Parameters.new(person: { name: 'Francesco' }).require(:person) # # => {"name"=>"Francesco"} # - # ActionController::Parameters.new(person: {}).require(:person) - # # => ActionController::EmptyParameter: value is empty for required key: person + # ActionController::Parameters.new(person: nil).require(:person) + # # => ActionController::ParameterMissing: param not found: person # - # ActionController::Parameters.new(name: {}).require(:person) + # ActionController::Parameters.new(person: {}).require(:person) # # => ActionController::ParameterMissing: param not found: person def require(key) - raise(ActionController::ParameterMissing.new(key)) unless self.key?(key) - self[key].presence || raise(ActionController::EmptyParameter.new(key)) + self[key].presence || raise(ParameterMissing.new(key)) end # Alias of #require. |