Rails 3.0 中的默认验证错误消息在哪里? [英] Where are Default Validation Error Messages in Rails 3.0?

查看:52
本文介绍了Rails 3.0 中的默认验证错误消息在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails 3.0 中的默认验证错误消息在哪里?例如,ActiveRecord::Error.default_error_messages[:taken] 的等价物是什么?我已经发现 ActiveModel 处理错误而不是 ActiveRecord,但我自己找不到错误.

Where are the default validation error messages in Rails 3.0? What is the equivalent of ActiveRecord::Error.default_error_messages[:taken], for example? I have gotten as far as finding that ActiveModel handles the errors rather than ActiveRecord, but I can't find the errors themselves.

推荐答案

http://github.com/rails/rails/blob/master/activemodel/lib/active_model/locale/en.yml

http://github.com/rails/rails/blob/master/activerecord/lib/active_record/locale/en.yml

:D

更新:

也许您应该尝试添加自己的自定义错误消息?

Maybe you should try to add your own custom error messages?

# de.yml
activerecord:
  errors:
    messages:
      taken: "ist bereits vergeben"

# test_spec.rb
...
assert_equal(object.errors[field], I18n.t("activerecord.errors.messages.taken"))
...

这篇关于Rails 3.0 中的默认验证错误消息在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆