Skip to content

Commit 593a09d

Browse files
committed
Add brief summary of strict validations added in 3.2.
1 parent 03a6119 commit 593a09d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

railties/guides/source/active_record_validations_callbacks.textile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ end
141141

142142
+invalid?+ is simply the inverse of +valid?+. +invalid?+ triggers your validations, returning true if any errors were found in the object, and false otherwise.
143143

144+
h4. Strict Validations
145+
146+
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.
147+
148+
<ruby>
149+
class Person < ActiveRecord::Base
150+
validates :name, :presence => {:strict => true}
151+
end
152+
153+
>> p = Person.new
154+
>> p.valid?
155+
=> ActiveModel::StrictValidationFailed: can't be blank
156+
</ruby>
157+
144158
h4(#validations_overview-errors). +errors[]+
145159

146160
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.

0 commit comments

Comments
 (0)