简体   繁体   English

设计自定义错误消息

[英]Devise Custom Error Messages

I know that you can use the devise.en.yml locale to set custom error messages but message like "Password can't be blank" or "Email can't be blank" aren't in the locale to be customized. 我知道您可以使用devise.en.yml语言环境设置自定义错误消息,但是“自定义密码不能为空”或“电子邮件不能为空白”之类的消息不在要自定义的语言环境中。 Is there anyway to change those? 反正有改变这些吗?

After reading I found that I can use: 阅读后,我发现我可以使用:

en:
  mongoid:
    errors:
      models:
        user:
          attributes:
            email:
              blank: "custom invalid message"

But now the message reads "Email custom invalid message". 但是现在该消息显示为“通过电子邮件发送自定义无效消息”。 How come the name of the field is added to the beginning of the custom message? 字段名称如何添加到自定义消息的开头? Is there anyway to change this behavior? 无论如何,有没有改变这种行为?

Try it: 试试吧:

en:
  mongoid:
    attributes:
      user:
        email: 'Your name for email'

'user' is the model and 'email' the field you want to translate. “用户”是模型,“电子邮件”是您要翻译的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM