提交 d163d3bf 编写于 作者: K Karthik Muthupalaniappan

outline two ways to invoke a custom active model validator

上级 8611f14c
......@@ -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?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册