diff options
author | Carl Lerche <me@carllerche.com> | 2011-02-05 16:44:35 -0800 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2011-02-05 16:44:35 -0800 |
commit | cd13fbd8d8071b822f6d4f8967ef80c617c036ba (patch) | |
tree | 5f93f68a4f5ae6bf285fb3eb7604a647294d165d /activemodel/lib/active_model/validations/with.rb | |
parent | e9e9ed6b60a42a7c3afe3c4a9f8cf6d1e5422e59 (diff) | |
download | rails-cd13fbd8d8071b822f6d4f8967ef80c617c036ba.tar.gz rails-cd13fbd8d8071b822f6d4f8967ef80c617c036ba.tar.bz2 rails-cd13fbd8d8071b822f6d4f8967ef80c617c036ba.zip |
Optionally pass in the attribute being validated to an instance method validator
Diffstat (limited to 'activemodel/lib/active_model/validations/with.rb')
-rw-r--r-- | activemodel/lib/active_model/validations/with.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb index 16d81263a2..1663697727 100644 --- a/activemodel/lib/active_model/validations/with.rb +++ b/activemodel/lib/active_model/validations/with.rb @@ -10,7 +10,13 @@ module ActiveModel class WithValidator < EachValidator def validate_each(record, attr, val) - record.send options[:with] + method_name = options[:with] + + if record.method(method_name).arity == 0 + record.send method_name + else + record.send method_name, attr + end end end |