我在服務類中有這個驗證:
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 上找不到這種用法的任何示例。有誰知道如何翻譯這個驗證?
uj5u.com熱心網友回復:
來自 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"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/453760.html
標籤:轨道上的红宝石 错误处理 本土化 国际化 导轨-i18n
