我需要为其编写自定义错误的自定义模型名称Xyz。在验证器内部,我使用以下语法
class XyzValidator
include activeModel::Model
validate :method_name
def method_name
# what should the syntax there for errors.add ?
errors.add(:base,:method_name)
end
end
在我的errors.yml文件中,我有类似的内容。
en:
activemodel:
errors:
models:
xyz_validator:
attributes:
base:
method_name:
code: "XY11"
message: "%{name} is wrong."
这里如何用任何自定义名称替换名称? .errors.add的语法应该是什么?如何在yml文件中向此 message 发送多个参数?