diff options
author | Karthik Muthupalaniappan <karthik.swaminathan@gmail.com> | 2011-11-04 15:18:37 +0530 |
---|---|---|
committer | Karthik Muthupalaniappan <karthik.swaminathan@gmail.com> | 2011-11-04 15:18:37 +0530 |
commit | d163d3bf7ebb98d90977974aed8f85b7ec678afd (patch) | |
tree | 6c7f453500124442ba8b7a6b717b079007d5eea8 | |
parent | 8611f14cafea0e2fcfddd9d22cca442c31664940 (diff) | |
download | rails-d163d3bf7ebb98d90977974aed8f85b7ec678afd.tar.gz rails-d163d3bf7ebb98d90977974aed8f85b7ec678afd.tar.bz2 rails-d163d3bf7ebb98d90977974aed8f85b7ec678afd.zip |
outline two ways to invoke a custom active model validator
-rw-r--r-- | activemodel/README.rdoc | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc index 67701bc422..fa3353a780 100644 --- a/activemodel/README.rdoc +++ b/activemodel/README.rdoc @@ -162,13 +162,21 @@ modules: {Learn more}[link:classes/ActiveModel/Validations.html] * Custom validators - + class Person include ActiveModel::Validations validates_with HasNameValidator attr_accessor :name end + class Person + include ActiveModel::Validations + validates :name, :has_name => true + attr_accessor :name + end + + You could use any of the two ways mentioned above to use a Custom Validator. + class HasNameValidator < ActiveModel::Validator def validate(record) record.errors[:name] = "must exist" if record.name.blank? |