Module

ClassMethods

All of the following validations are defined in the class scope of the model that you’re interested in validating. They offer a more declarative way of specifying when the model is valid and when it is not. It is recommended to use these over the low-level calls to validate and validate_on_create when possible.

Constants
ALL_NUMERICALITY_CHECKS
ALL_RANGE_OPTIONS
DEFAULT_VALIDATION_OPTIONS
Public Methods
condition_block?
create! Creates an object just like Base.create but calls save! instead of save so an exception is raised if the record is invalid.
evaluate_condition Determine from the given condition (whether a block, procedure, method or string) whether or not to validate the record. See #validates_each.
validate Adds a validation method or block to the class. This is useful when overriding the #validate instance method becomes too unwieldly and you’re looking for more descriptive declaration of your validations.
validate_on_create
validate_on_update
validates_acceptance_of Encapsulates the pattern of wanting to validate the acceptance of a terms of service check box (or similar agreement). Example:
validates_associated Validates whether the associated object or objects are all valid themselves. Works with any kind of association.
validates_confirmation_of Encapsulates the pattern of wanting to validate a password or email address field with a confirmation. Example:
validates_each Validates each attribute against a block.
validates_exclusion_of Validates that the value of the specified attribute is not in a particular enumerable object.
validates_format_of Validates whether the value of the specified attribute is of the correct form by matching it against the regular expression provided.
validates_inclusion_of Validates whether the value of the specified attribute is available in a particular enumerable object.
validates_length_of Validates that the specified attribute matches the length restrictions supplied. Only one option can be used at a time:
validates_numericality_of Validates whether the value of the specified attribute is numeric by trying to convert it to a float with Kernel.Float (if integer is false) or applying it to the regular expression /\A[+\-]?\d+\Z/ (if integer is set to true).
validates_presence_of Validates that the specified attributes are not blank (as defined by Object#blank?). Happens by default on save. Example:
validates_size_of Alias for #validates_length_of
validates_uniqueness_of Validates whether the value of the specified attributes are unique across the system. Useful for making sure that only one user can be named "davidhh".
Private Methods
validation_method
write_inheritable_set
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.