Rails i18n - 无法更改错误格式

Rails i18n - Can't change the format of the errors

在我的 Rails 应用程序中,我有以下翻译

de:
  activerecord:
    errors:
      models:
        applicant:
          attributes:
            name:
              blank: "Bitte nenne uns Deinen %{attribute}"

但是当我检查模型的错误时,我收到以下消息:

Applicant name Bitte nenne uns Deinen Name

邮件开头怎么有那个"Applicant Name"?

我该如何删除它?

您必须使用 full_messages 来显示错误。像这样:

applicant.errors.full_messages
#=> ["Applicant name Bitte nenne uns Deinen Name"]

改为

applicant.errors.messages
#=> ["Bitte nenne uns Deinen Name"]

注意: full_messages 将在错误消息之前附加属性名称。这就是为什么您将 Applicant name 附加到消息

解决方案2

如果你想改变full_messages然后尝试改变

en:
  errors:
    format: "%{attribute} %{message}"

en:
  errors:
    format: "%{message}"