我有三种型号Account
,User
和AccountPermission
。嵌套属性中的错误消息
我在创建用户时通过AccountPermission
创建Account
。
但是,如果发生与Account:name相关的问题,系统会抛出类似于下面的内容。
Account permissions account name has already been taken
所以,我只需要修正此错误消息。
我试着给我的验证添加一个消息属性。它只是附加到实际的消息。
我也试过locale的东西。还只是追加
en:
activerecord:
errors:
models:
account:
attributes:
name:
taken: 'bla bla'
据我所知,在ActiveModel
。此消息的结构从下面
区域/ en.yml加载ActiveModel中
en:
errors:
format: "%{attribute} %{message}"
那么,有什么办法编辑此消息无痛人流?如果我甚至删除了模型名称,这就够了。
你要问你可以抛出一个自定义错误消息时验证失败? –