diff options
author | Xavier Noria <fxn@hashref.com> | 2011-04-19 21:54:10 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2011-04-19 21:54:10 +0200 |
commit | e162e912c9f2b3ed5789a2d262c7962a67fb6b5d (patch) | |
tree | fbcbe9039276b5f652d143e5eb527b6fa14f2182 /railties/guides/source/active_record_validations_callbacks.textile | |
parent | a19c260038a9b5b688a2e8d883b604983ac59eae (diff) | |
parent | ad602869260b4233f7471f8aa467d3b83ffeb801 (diff) | |
download | rails-e162e912c9f2b3ed5789a2d262c7962a67fb6b5d.tar.gz rails-e162e912c9f2b3ed5789a2d262c7962a67fb6b5d.tar.bz2 rails-e162e912c9f2b3ed5789a2d262c7962a67fb6b5d.zip |
Merge branch 'master' of git://github.com/lifo/docrails
Conflicts:
railties/guides/source/ajax_on_rails.textile
railties/guides/source/generators.textile
Diffstat (limited to 'railties/guides/source/active_record_validations_callbacks.textile')
-rw-r--r-- | railties/guides/source/active_record_validations_callbacks.textile | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index c65dd52e48..9aab4b6694 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -552,6 +552,21 @@ class Account < ActiveRecord::Base end </ruby> +h4. Grouping conditional validations + +Sometimes it is useful to have multiple validations use one condition, it can be easily achieved using +with_options+. + +<ruby> +class User < ActiveRecord::Base + with_options :if => :is_admin? do |admin| + admin.validates_length_of :password, :minimum => 10 + admin.validates_presence_of :email + end +end +</ruby> + +All validations inside of +with_options+ block will have automatically passed the condition +:if => :is_admin?+ + h3. Creating Custom Validation Methods When the built-in validation helpers are not enough for your needs, you can write your own validation methods. |