diff options
author | Obie Fernandez <obie@hashrocket.com> | 2010-09-20 21:35:41 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-24 12:49:16 +0200 |
commit | 275f922a23b780600a32f70de5b661371c8ffdf4 (patch) | |
tree | a49898a3284e4508768eefa9567e0cf105786f7a /activemodel/test/models | |
parent | 097240f60215b866d24aebd02cc4159bdc6e7451 (diff) | |
download | rails-275f922a23b780600a32f70de5b661371c8ffdf4.tar.gz rails-275f922a23b780600a32f70de5b661371c8ffdf4.tar.bz2 rails-275f922a23b780600a32f70de5b661371c8ffdf4.zip |
Better shortcut options for custom validators [#5672 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activemodel/test/models')
-rw-r--r-- | activemodel/test/models/person_with_validator.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activemodel/test/models/person_with_validator.rb b/activemodel/test/models/person_with_validator.rb index f6f665ccee..505ed880c1 100644 --- a/activemodel/test/models/person_with_validator.rb +++ b/activemodel/test/models/person_with_validator.rb @@ -7,5 +7,18 @@ class PersonWithValidator end end + class LikeValidator < ActiveModel::EachValidator + def initialize(options) + @with = options[:with] + super + end + + def validate_each(record, attribute, value) + unless value[@with] + record.errors.add attribute, "does not appear to be like #{@with}" + end + end + end + attr_accessor :title, :karma end |