Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
outline two ways to invoke a custom active model validator
  • Loading branch information
kmuthupa committed Nov 4, 2011
1 parent 8611f14 commit d163d3b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion activemodel/README.rdoc
Expand Up @@ -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?
Expand Down

0 comments on commit d163d3b

Please sign in to comment.