views:

139

answers:

1

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.

+2  A: 

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

and

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

:D

UPDATE:

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"))
...
Lichtamberg
Thank you, that's another useful bit of information. But how do I access the information in a Rails program? There must be a method in ActiveModel::Errors or somewhere else, isn't there?
Mike Blyth
What do you want to do exactly?
Lichtamberg
For example, assert_equal(object.errors[field], ActiveRecord::Error.default_error_messages[:taken]) to test that the right error message has been given. It's not pragmatically that important to me, I can just use a text literal, but it doesn't seem the "pure" way to do things.
Mike Blyth
Updated my post.
Lichtamberg