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.

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): stackoverflow.com/questions/808547/… Commented Sep 27, 2010 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! Commented Sep 27, 2010 at 22:52

1 Answer 1

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"))
...
Sign up to request clarification or add additional context in comments.

3 Comments

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?
What do you want to do exactly?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.