From ffe16b16cd8ca4fa838a08407b275a38b42b5dbc Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sat, 23 Jun 2012 14:49:22 -0500 Subject: =?UTF-8?q?add=20description=20ActiveModel::StrictValidationField?= =?UTF-8?q?=C2=A0[ci=20skip]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- activemodel/lib/active_model/errors.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index cfdd4d615d..7ee86d6444 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -281,6 +281,14 @@ module ActiveModel # # If +message+ is a proc, it will be called, allowing for things like # Time.now to be used within an error. + # + # If the :strict option is set to true will raise + # ActiveModel::StrictValidationFailed instead of adding the error. + # + # person.errors.add(:name, nil, strict: true) + # # => ActiveModel::StrictValidationFailed: name is invalid + # + # person.errors.messages # => {} def add(attribute, message = nil, options = {}) message = normalize_message(attribute, message, options) if options[:strict] @@ -427,6 +435,8 @@ module ActiveModel end end + # Raised when a validation cannot be corrected by end users and are considered + # exceptional class StrictValidationFailed < StandardError end end -- cgit v1.2.3