Rails i18n ActiveModel:翻译缺席验证的错误消息
Rails i18n ActiveModel: Translate error message for absence validation
我在服务中进行了此验证 class:
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"
但是当我重现测试用例时,错误信息是Frozen identification data must be blank
。我假设 absence
在这里是不正确的,但我在 Google 上找不到这种用法的任何示例。有谁知道如何翻译这个验证?
来自rails 指南: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"
我在服务中进行了此验证 class:
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"
但是当我重现测试用例时,错误信息是Frozen identification data must be blank
。我假设 absence
在这里是不正确的,但我在 Google 上找不到这种用法的任何示例。有谁知道如何翻译这个验证?
来自rails 指南: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"