mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added information about the new Object#invalid? method just added to Edge.
This commit is contained in:
parent
336f0a2e63
commit
2bf922d056
1 changed files with 5 additions and 1 deletions
|
@ -137,7 +137,11 @@ end
|
|||
=> ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
|
||||
</ruby>
|
||||
|
||||
To verify whether or not a particular attribute of an object is valid, you can use the +invalid?+ method. This method is only useful _after_ validations have been run, because it only inspects the errors collection and does not trigger validations itself. It's different from the +valid?+ method because it doesn't verify the validity of the object as a whole, but only if there are errors found on an individual attribute of the object.
|
||||
+Object#invalid?+ is simply the inverse of +Object#valid?+. +invalid?+ triggers your validations and returns true if any errors were added to the object, and false otherwise.
|
||||
|
||||
h3. +errors.invalid?+
|
||||
|
||||
To verify whether or not a particular attribute of an object is valid, you can use the +errors.invalid?+ method. This method is only useful _after_ validations have been run, because it only inspects the errors collection and does not trigger validations itself. It's different from the +valid?+ method because it doesn't verify the validity of the object as a whole, but only if there are errors found on an individual attribute of the object.
|
||||
|
||||
<ruby>
|
||||
class Person < ActiveRecord::Base
|
||||
|
|
Loading…
Reference in a new issue