From 30a789429948886f0ef7d8204420277c68ab4d18 Mon Sep 17 00:00:00 2001 From: CassioMarques Date: Fri, 7 Nov 2008 23:59:36 -0200 Subject: Some more text on validates_confirmation_of, added some more about validations helpers too --- railties/doc/guides/source/activerecord_validations_callbacks.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/doc/guides/source/activerecord_validations_callbacks.txt') diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt index 58e378ab24..f05628302d 100644 --- a/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -57,6 +57,8 @@ For verifying if an object is valid, Active Record uses the +valid?+ method, whi Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers create validations rules that are commonly used in most of the applications that you'll write, so you don't need to recreate it everytime, avoiding code duplication, keeping everything organized and boosting your productivity. Everytime a validation fails, an error message is added to the object's +errors+ collection, this message being associated with the field being validated. +Each helper accepts an arbitrary number of attributes, received as symbols, so with a single line of code you can add the same kind of validation to several attributes. + All these helpers accept the +:on+ and +:message+ options, which define when the validation should be applied and what message should be added to the +errors+ collection when it fails, respectively. The +:on+ option takes one the values +:save+ (it's the default), +:create+ or +:update+. There is a default error message for each one of the validation helpers. These messages are used when the +:message+ option isn't used. Let's take a look at each one of the available helpers, listed in alphabetic order. === The +validates_acceptance_of+ helper @@ -117,7 +119,7 @@ In your view template you could use something like <%= text_field :person, :email_confirmation %> ------------------------------------------------------------------ -NOTE: This check is performed only if +email_confirmation+ is not nil, and by default only on save. To require confirmation, make sure to add a presence check for the confirmation attribute: +NOTE: This check is performed only if +email_confirmation+ is not nil, and by default only on save. To require confirmation, make sure to add a presence check for the confirmation attribute (we'll take a look at +validates_presence_of+ later on this guide): [source, ruby] ------------------------------------------------------------------ -- cgit v1.2.3