17

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.

Mike Blyth
  • 4,158
  • 4
  • 30
  • 41
  • While this may not fully answer your question it provides you a way to customize the validation error messages (assuming that it's what you're trying to do): http://stackoverflow.com/questions/808547/fully-custom-validation-error-message-with-rails – rogeriopvl Sep 27 '10 at 22:45
  • Actually, I'm not trying to customize them but just to use them in testing, making sure that the right error messages are raised. However, the link you gave is useful--it appears it's more complicated and less intuitive to created customized messages than in earlier versions! – Mike Blyth Sep 27 '10 at 22:52

1 Answers1

24

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"))
...
BvuRVKyUVlViVIc7
  • 11,641
  • 9
  • 59
  • 111
  • 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 Sep 28 '10 at 07:58
  • What do you want to do exactly? – BvuRVKyUVlViVIc7 Sep 28 '10 at 12:08
  • 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 Sep 29 '10 at 22:12