排除错误消息前面的属性名称 [英] Exclude attribute name prepending in error message

查看:50
本文介绍了排除错误消息前面的属性名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的国际化方式:

I have a simple internationalization:

attributes:
  user:
    login: Login
errors:
  template:
    header: "Errors"
    body: ""
  models:
    user:
      attributes:
       login:
         taken: "The chosen {{attribute}} is already registered"

结果错误消息如下:

登录所选的登录名已经注册

Login The chosen Login is already registered

看来,就像Rails会自动在错误消息前加上属性名称一样.这迫使我只能以一种方式安排邮件-以属性名称作为第一个单词.

It seems, like Rails automatically prepends the error messsage with attribute name. This forces me to arrange messages in only one way - with attribute name as a first word.

我需要以下错误消息:

所选登录名已经注册

The chosen Login is already registered

如何配置Rails不在属性名前添加错误消息?

How can I configure Rails to not prepend the error message with the attribute name?

推荐答案

您需要指定错误消息格式以删除型号名称.我相信这仅在Rails 3.2.6及更高版本中可行. 在Rails指南中的I18n一章中有更多详细信息.

You need to specify the error message format in order to remove the model name. I believe this is only possible as of Rails 3.2.6 and up. There are more details on the I18n chapter in Rails Guides.

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

默认值为%{attribute} %{message}.

这篇关于排除错误消息前面的属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆