Browse files

Added information about grouping conditional validations

  • Loading branch information...
1 parent 50b2eb8 commit 8c68bcf829ead305e2459c2b90850b43464ec7d7 @mpapis mpapis committed Apr 16, 2011
Showing with 15 additions and 0 deletions.
  1. +15 −0 railties/guides/source/active_record_validations_callbacks.textile
15 railties/guides/source/active_record_validations_callbacks.textile
@@ -552,6 +552,21 @@ class Account < ActiveRecord::Base
+h4. Grouping conditional validations
+Sometimes it is useful to have multiple validations use one condition, it can be easily achieved using +with_options+.
+class User < ActiveRecord::Base
+ with_options :if => :is_admin? do |admin|
+ admin.validates_length_of :password, :minimum => 10
+ admin.validates_presence_of :email
+ end
+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.

0 comments on commit 8c68bcf

Please sign in to comment.