Rails validation defines valid states for each of your Active Record model classes. They are used to ensure that only valid details are entered into your database. Rails make it easy to add validations to your model classes and allows you to create your own validation methods as well. Using built-in validation DSL, you can do several kinds of validations.
When an Active Record model class fails a validation, it is considered an error. Each Active Record model class maintains a collection of errors, which display appropriate error information to the users when validation error occurs.
Rails built-in Validation Methods
The following Rails methods skip validations and save the object to the database regardless of its validity. They should be used with caution.
valid? and invalid?
Before saving an Active Record object, a validation is done by Rails. If any error is produced, object is not saved.
The valid? triggers your validations, returns true if no errors are found and false otherwise.
The invalid? is simply the reverse of valid?. It triggers your validations, returns true if invalid and false otherwise.
Next TopicRuby on rails ajax