我可以本地化每个验证的错误消息,但是如何为特定的模型创建一个错误.
@H_404_11@解决方法
普通地区如下所示:
en: mongoid: errors: messages: taken: "It is already taken"
但是我想要更改用户模型的消息:
en: mongoid: errors: messages: taken: "It is already taken" user: taken: "It is already taken. %{link_to 'Remember password',reset_password_path'}"
尝试这个:
en: mongoid: errors: messages: taken: "It is already taken" models: user: attributes: login: taken: "It is already taken. %{link}"
参考:
PS:
本地化字符串应使用插值变量进行动态替换.
user.errors.add(:login,:taken,:link => "foo")