diff options
Diffstat (limited to 'railties/doc/guides/source')
| -rw-r--r-- | railties/doc/guides/source/activerecord_validations_callbacks.txt | 13 |
1 files changed, 13 insertions, 0 deletions
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 |
