aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/active_record_validations_callbacks.textile
diff options
context:
space:
mode:
authorBogdan Gusiev <agresso@gmail.com>2012-08-06 13:45:27 +0300
committerBogdan Gusiev <agresso@gmail.com>2012-08-06 13:45:27 +0300
commit2e4f7986b8ec90d7b41c385388be21b8cee79b9c (patch)
treed7dd64e1c97b9dcf1c263ebd2bd408b7fd7c9208 /guides/source/active_record_validations_callbacks.textile
parent5edfc463484827df364a1e589677d5c84dfac282 (diff)
downloadrails-2e4f7986b8ec90d7b41c385388be21b8cee79b9c.tar.gz
rails-2e4f7986b8ec90d7b41c385388be21b8cee79b9c.tar.bz2
rails-2e4f7986b8ec90d7b41c385388be21b8cee79b9c.zip
AM::Validation#validates: ability to pass custom exception to `:strict` option
Diffstat (limited to 'guides/source/active_record_validations_callbacks.textile')
-rw-r--r--guides/source/active_record_validations_callbacks.textile10
1 files changed, 10 insertions, 0 deletions
diff --git a/guides/source/active_record_validations_callbacks.textile b/guides/source/active_record_validations_callbacks.textile
index cf7293bd9e..b866337e3f 100644
--- a/guides/source/active_record_validations_callbacks.textile
+++ b/guides/source/active_record_validations_callbacks.textile
@@ -532,6 +532,16 @@ end
Person.new.valid? => ActiveModel::StrictValidationFailed: Name can't be blank
</ruby>
+There is also an ability to pass custom exception to +:strict+ option
+
+<ruby>
+class Person < ActiveRecord::Base
+ validates :token, :presence => true, :uniqueness => true, :strict => TokenGenerationException
+end
+
+Person.new.valid? => TokenGenerationException: Token can't be blank
+</ruby>
+
h3. Conditional Validation
Sometimes it will make sense to validate an object just when a given predicate is satisfied. You can do that by using the +:if+ and +:unless+ options, which can take a symbol, a string, a +Proc+ or an +Array+. You may use the +:if+ option when you want to specify when the validation *should* happen. If you want to specify when the validation *should not* happen, then you may use the +:unless+ option.