Rails i18n ActiveModel:翻译缺席验证的错误消息
我在服务类中有此验证:
class Users::Updater
include ActiveModel::Validations
validates(:frozen_identification_data, absence: { message: 'Identification fields cannot be changed at this time' } )
end
我正在尝试将此错误消息移至Locales文件中:
en:
activemodel:
errors:
users/updater:
attributes:
frozen_identification_data:
absence: "Identification fields cannot be changed at this time"
但是,当我重现测试用例时,错误消息为冷冻标识数据必须为空白
。我假设缺席
在这里不正确,但是我在Google上找不到任何示例。有人知道如何翻译此验证吗?
I have this validation in a service class:
class Users::Updater
include ActiveModel::Validations
validates(:frozen_identification_data, absence: { message: 'Identification fields cannot be changed at this time' } )
end
I'm trying to move this error message into a locales file:
en:
activemodel:
errors:
users/updater:
attributes:
frozen_identification_data:
absence: "Identification fields cannot be changed at this time"
But when I reproduce the test case, the error message is Frozen identification data must be blank
. I'm assuming absence
is incorrect here, but I can't find any examples of this usage on Google. Does anyone know how to translate this validation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 Rails 指南: https://guides.rubyonrails.org/i18n.html# error-message-interpolation
对于
absence
,键应该是present
:From rails guides: https://guides.rubyonrails.org/i18n.html#error-message-interpolation
For
absence
the key should bepresent
: