Where are Default Validation Error Messages in Rails 3.0?
Asked Answered
C

1

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.

Camphorate answered 27/9, 2010 at 22:23 Comment(2)
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): #809047Quittance
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!Camphorate
P
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"))
...
Persephone answered 28/9, 2010 at 0:26 Comment(3)
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?Camphorate
What do you want to do exactly?Persephone
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.Camphorate

© 2022 - 2024 — McMap. All rights reserved.