From 2e4f7986b8ec90d7b41c385388be21b8cee79b9c Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Mon, 6 Aug 2012 13:45:27 +0300 Subject: AM::Validation#validates: ability to pass custom exception to `:strict` option --- guides/source/active_record_validations_callbacks.textile | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'guides/source/active_record_validations_callbacks.textile') 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 +There is also an ability to pass custom exception to +:strict+ option + + +class Person < ActiveRecord::Base + validates :token, :presence => true, :uniqueness => true, :strict => TokenGenerationException +end + +Person.new.valid? => TokenGenerationException: Token can't be blank + + 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. -- cgit v1.2.3