提问人:Libby 提问时间:3/29/2022 更新时间:3/30/2022 访问量:599
Rails i18n ActiveModel:翻译缺失验证的错误消息
Rails i18n ActiveModel: Translate error message for absence validation
问:
我在服务类中有此验证:
class Users::Updater
include ActiveModel::Validations
validates(:frozen_identification_data, absence: { message: 'Identification fields cannot be changed at this time' } )
end
我正在尝试将此错误消息移动到语言环境文件中:
en:
activemodel:
errors:
users/updater:
attributes:
frozen_identification_data:
absence: "Identification fields cannot be changed at this time"
但是当我重现测试用例时,错误消息是 .我假设这里是不正确的,但我在 Google 上找不到任何这种用法的例子。有谁知道如何翻译此验证?Frozen identification data must be blank
absence
答:
1赞
Deepesh
3/30/2022
#1
从导轨:https://guides.rubyonrails.org/i18n.html#error-message-interpolation
对于密钥应为:absence
present
en:
activemodel:
errors:
users/updater:
attributes:
frozen_identification_data:
present: "Identification fields cannot be changed at this time"
评论
absence
present