aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Legg <oliver.legg@mac.com>2012-02-27 22:15:01 +0000
committerOliver Legg <oliver.legg@mac.com>2012-02-27 22:15:01 +0000
commit593a09d3b9aea53be5e56006c1be140091674db7 (patch)
tree92f8502dfb329251bacddd7d875c6c07dc783097
parent03a6119e3bc4394d6a150fc07e13ceaa6ed44127 (diff)
downloadrails-593a09d3b9aea53be5e56006c1be140091674db7.tar.gz
rails-593a09d3b9aea53be5e56006c1be140091674db7.tar.bz2
rails-593a09d3b9aea53be5e56006c1be140091674db7.zip
Add brief summary of strict validations added in 3.2.
-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.