如何将自定义错误添加到用户错误集合? [英] How to add custom errors to the User errors collection?
本文介绍了如何将自定义错误添加到用户错误集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何手动向 User
模型添加错误?
How can I add errors to the User
model manually?
它只是 这里有一些文字"@user.errors
?
推荐答案
@user.errors.add(:email, "Not valid")
如果你不想使用任何属性,那么在你的模型中
If you don't want to use any attributes, then in your model
@user.errors[:base] << "This person is invalid because ..."
详情:链接
这篇关于如何将自定义错误添加到用户错误集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文