diff options
author | CassioMarques <cassiommc@gmail.com> | 2009-01-08 21:00:16 -0200 |
---|---|---|
committer | CassioMarques <cassiommc@gmail.com> | 2009-01-08 21:00:16 -0200 |
commit | afdacd0857886a021ff68e8238876daec82efefb (patch) | |
tree | 8a92649f6387616e9aa1225b78f430f960c2058a /railties/doc/guides/source | |
parent | 2c2824a967a18d7f7a7622f24a9e3be4db851bf8 (diff) | |
download | rails-afdacd0857886a021ff68e8238876daec82efefb.tar.gz rails-afdacd0857886a021ff68e8238876daec82efefb.tar.bz2 rails-afdacd0857886a021ff68e8238876daec82efefb.zip |
Moved validates_each to the last position of it's section. Added VIM swap files to .gitignore
Diffstat (limited to 'railties/doc/guides/source')
-rw-r--r-- | railties/doc/guides/source/activerecord_validations_callbacks.txt | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt index ff2acdf8d5..9865aeebb0 100644 --- a/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -133,21 +133,6 @@ end The default error message for +validates_confirmation_of+ is "_doesn't match confirmation_" -=== 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 This helper validates that the attributes' values are not included in a given set. In fact, this set can be any enumerable object. @@ -301,6 +286,21 @@ end The default error message for +validates_uniqueness_of+ is "_has already been taken_". +=== 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. + == Common validation options There are some common options that all the validation helpers can use. Here they are, except for the +:if+ and +:unless+ options, which we'll cover right at the next topic. |