默认 ActiveRecord/ActiveModel ::错误是匿名的
默认 ActiveModel::Errors 很棒,但我正在解决问题,即消息是匿名的。例如,有消息应该看起来像电子邮件地址。
属于电子邮件
字段,但我想要知道此错误消息是格式 类型。另一条消息
与确认不匹配
是确认
类型。
#<ActiveModel::Errors:0x000001054abef0 @base=#<User ... >,
@messages={
:password=>["doesn't match confirmation"],
:email=>["should look like an email address."]}>
有没有更好的错误的宝石,或者你们有人知道猴子补丁吗?
谢谢
Default ActiveModel::Errors are great, but i am solving problem, that the messages are anonymous. For example there is message should look like an email address.
that belongs to email
field, but what i want is to know that this error message is format
type. And the other message doesn't match confirmation
is confirmation
type.
#<ActiveModel::Errors:0x000001054abef0 @base=#<User ... >,
@messages={
:password=>["doesn't match confirmation"],
:email=>["should look like an email address."]}>
Is there any gem for better errors, or do any of you have idea of monkey patch?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Rails 验证中,您可以添加自定义消息,以将模型生成的异常食物链向上传递。
ActiveRecord 验证
In rails validations, you can add custom messages to be passed up the exception food chain, generated from the model.
ActiveRecord validations