i keep forgetting that, so i post it here for me and everyone else.
Here is the list of validations which you can perform on user input:
validates_presence_of:
Following check that last_name and first_name should be filled and should not be NOLL.
validates_presence_of :firstname, :lastname |
validates_length_of:
Following example shows various validations on a single filed. These validations can be performed separately.
validates_length_of :password, |
validates_acceptance_of:
Following will accept only 'Y' value for option field.
validates_acceptance_of :option |
validates_confirmation_of:
The fields password and password_confirmation must match and will be used as follows:
validates_confirmation_of :password |
validates_uniqueness_of:
Following puts a condition for user_name to be unique.
validates_uniqueness_of :user_name |
validates_format_of:
Following validates a that given email ID is in a valid format. This shows how you can use regualr expression to validatea filed.
validates_format_of :email |
validates_numericality_of:
This validates that given field is numeric.
validates_numericality_of :value |
validates_inclusion_of:
Following checks that passed value is an enumeration and falls in the given range.
validates_inclusion_of :gender, |
validates_exclusion_of:
Following checks that given values does not fall in the given range.
validates_exclusion_of :age |
validates_inclusion_of:
Following checks that given values should fall in the given range. This is opposite to validates_exclusion_of.
validates_inclusion_of :age |
validates_associated:
This validates that the associated object is valid.
Options for all Validations:
You can use following options alongwith all the validations.
:message => 'my own errormessage' Use this to print a custom error message in case of validation fails.
:on => :create or :update This will be used in such cases where you want to perform validation only when record is being created or updated. So if you use :create then this validation work only when there is a create opration on database.
Check the following link for more detail on Validations.
0 comments:
Post a Comment