From 172f3ce35084ac7ae9f37e8cecea00909560a70d Mon Sep 17 00:00:00 2001 From: CassioMarques Date: Sat, 8 Nov 2008 10:32:52 -0200 Subject: Added documentation for validates_each --- .../doc/guides/html/activerecord_validations_callbacks.html | 13 +++++++++++++ .../guides/source/activerecord_validations_callbacks.txt | 13 +++++++++++++ 2 files changed, 26 insertions(+) (limited to 'railties/doc') diff --git a/railties/doc/guides/html/activerecord_validations_callbacks.html b/railties/doc/guides/html/activerecord_validations_callbacks.html index a16fbaad05..30e8a82889 100644 --- a/railties/doc/guides/html/activerecord_validations_callbacks.html +++ b/railties/doc/guides/html/activerecord_validations_callbacks.html @@ -429,6 +429,19 @@ http://www.gnu.org/software/src-highlite -->

The default error message for validates_confirmation_of is "doesn't match confirmation"

3.4. The validates_each helper

+

This helper validates attributes against a block. It doesn't have a predefined validation function. You should create one using a block, and every attribute passed to validates_each will be tested against it. In the following example, we don't want names and surnames to begin with lower case.

+
+
+
class Person < ActiveRecord::Base
+  validates_each :name, :surname do |model, attr, value|
+    model.errors.add(attr, 'Must start with upper case') if value =~ /^[a-z]/
+  end
+end
+
+

The block receives the model, the attribute's name and the attribute's value. If your validation fails, you can add an error message to the model, therefore making it invalid.

3.5. The validates_exclusion_of helper

3.6. The validates_format_of helper

3.7. The validates_inclusion_of helper

diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt index f05628302d..082832b809 100644 --- a/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -133,6 +133,19 @@ The default error message for +validates_confirmation_of+ is "_doesn't match con === The +validates_each+ helper +This helper validates attributes against a block. It doesn't have a predefined validation function. You should create one using a block, and every attribute passed to +validates_each+ will be tested against it. In the following example, we don't want names and surnames to begin with lower case. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_each :name, :surname do |model, attr, value| + model.errors.add(attr, 'Must start with upper case') if value =~ /^[a-z]/ + end +end +------------------------------------------------------------------ + +The block receives the model, the attribute's name and the attribute's value. If your validation fails, you can add an error message to the model, therefore making it invalid. + === The +validates_exclusion_of+ helper === The +validates_format_of+ helper -- cgit v1.2.3