aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations.rb
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2010-12-19 18:50:18 -0200
committerSantiago Pastorino <santiago@wyeworks.com>2010-12-19 18:50:18 -0200
commit5fb42ac478923c78ebc3e457acea4dc6726e3796 (patch)
tree3935569c3e44343f1b658906dd92a9c66e8edaf2 /activemodel/lib/active_model/validations.rb
parent08ccd29b5b1e3badc2176a8036fea138b774c38f (diff)
downloadrails-5fb42ac478923c78ebc3e457acea4dc6726e3796.tar.gz
rails-5fb42ac478923c78ebc3e457acea4dc6726e3796.tar.bz2
rails-5fb42ac478923c78ebc3e457acea4dc6726e3796.zip
Tests and docs which explain the use of validate with a block and without arguments
Diffstat (limited to 'activemodel/lib/active_model/validations.rb')
-rw-r--r--activemodel/lib/active_model/validations.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb
index b044caa8d3..6cb015a144 100644
--- a/activemodel/lib/active_model/validations.rb
+++ b/activemodel/lib/active_model/validations.rb
@@ -104,7 +104,7 @@ module ActiveModel
# end
# end
#
- # Or with a block which is passed with the current record to be validated:
+ # With a block which is passed with the current record to be validated:
#
# class Comment
# include ActiveModel::Validations
@@ -118,6 +118,16 @@ module ActiveModel
# end
# end
#
+ # Or with a block where self points to the current record to be validated:
+ #
+ # class Comment
+ # include ActiveModel::Validations
+ #
+ # validate do
+ # errors.add(:base, "Must be friends to leave a comment") unless commenter.friend_of?(commentee)
+ # end
+ # end
+ #
def validate(*args, &block)
options = args.extract_options!
if options.key?(:on)