提交 9a045585 编写于 作者: A Abdelkader Boudih

Merge pull request #19013 from y-yagi/custom_validators_example

use `messages` instead of deprecated `ActiveModel::Errors#[]=` method [ci skip]
......@@ -219,7 +219,7 @@ behavior out of the box:
class HasNameValidator < ActiveModel::Validator
def validate(record)
record.errors[:name] = "must exist" if record.name.blank?
record.errors.messages[:name] << "must exist" if record.name.blank?
end
end
......
......@@ -15,7 +15,7 @@ module ActiveModel
# class MyValidator < ActiveModel::Validator
# def validate(record)
# if some_complex_logic
# record.errors[:base] = "This record is invalid"
# record.errors.messages[:base] << "This record is invalid"
# end
# end
#
......
......@@ -1078,7 +1078,7 @@ Another way to do this is using `[]=` setter
```ruby
class Person < ActiveRecord::Base
def a_method_used_for_validation_purposes
errors[:name] = "cannot contain the characters !@#%*()_-+="
errors.messages[:name] << "cannot contain the characters !@#%*()_-+="
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册