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.
-
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/…rogeriopvl– rogeriopvl2010-09-27 22:45:32 +00:00Commented 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!Mike Blyth– Mike Blyth2010-09-27 22:52:57 +00:00Commented Sep 27, 2010 at 22:52
Add a comment
|
1 Answer
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"))
...
3 Comments
Mike Blyth
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?
BvuRVKyUVlViVIc7
What do you want to do exactly?
Mike Blyth
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.