aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/guides/source/active_record_validations_callbacks.textile14
1 files changed, 14 insertions, 0 deletions
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 72ac8d2db9..fc9a2ad30c 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -141,6 +141,20 @@ end
+invalid?+ is simply the inverse of +valid?+. +invalid?+ triggers your validations, returning true if any errors were found in the object, and false otherwise.
+h4. Strict Validations
+
+Rails can also be specify strict validations. You can use the +:strict+ option to set that validation as strict. If an object fails a strict validation then an +ActiveModel::StrictValidationFailed+ error message is raised.
+
+<ruby>
+class Person < ActiveRecord::Base
+ validates :name, :presence => {:strict => true}
+end
+
+>> p = Person.new
+>> p.valid?
+=> ActiveModel::StrictValidationFailed: can't be blank
+</ruby>
+
h4(#validations_overview-errors). +errors[]+
To verify whether or not a particular attribute of an object is valid, you can use +errors[:attribute]+. It returns an array of all the errors for +:attribute+. If there are no errors on the specified attribute, an empty array is returned.