2. The preamble
• All the code is available on github https://
github.com/ridget/validators_app
• @tjridge
• tomridge2@gmail.com
3. Validations are the bees
knees.
• Ensures only valid data is saved to the database
• Typically run before SQL insert/update commands sent to
the database.
• create/save/update methods trigger validations, if called
with a bang invalid records will return an exception, rather
than the object.
• Some methods like update_column and update_attribute
skip validation. save(:validate => false) skips validations
as well. Be as wary of these as you would be of good
reviews for a Michael Bay film.
4. Valid? Invalid?
• valid? Triggers validations, returns true if no errors are
found.
• invalid? Does the inverse.
• Object is valid if no errors found
• User.new could be technically invalid, but not return
any errors until save or valid? etc is called.
• Access error messages using .errors.messages
method on object.