aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-16 16:59:04 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-16 16:59:04 -0300
commitcfd7f4e9a09df137f1e78ae7194e969e4bacfd87 (patch)
tree633ea06abec347363d73548163f9fe8f83531a2f /guides
parent2a42b12d3b2ccfbdd14893cbc73f78ab229a34c2 (diff)
parent2e4f7986b8ec90d7b41c385388be21b8cee79b9c (diff)
downloadrails-cfd7f4e9a09df137f1e78ae7194e969e4bacfd87.tar.gz
rails-cfd7f4e9a09df137f1e78ae7194e969e4bacfd87.tar.bz2
rails-cfd7f4e9a09df137f1e78ae7194e969e4bacfd87.zip
Merge pull request #7024 from bogdan/strict_validation_custom_exception
AM::Validation#validates: custom exception for :strict option Conflicts: activemodel/CHANGELOG.md
Diffstat (limited to 'guides')
-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.