This project is archived and is in readonly mode.

#135 ✓resolved
Nathan Wilmes

Make ActiveRecord errors support full sentence messages

Reported by Nathan Wilmes | May 7th, 2008 @ 07:50 PM

Current Rails is extremely strict about what an attribute-specific error message looks like. A human-readable attribute name is always the first word(s) of the sentence, and a developer is only able to customize the sentence fragment after this word.

This makes it difficult to localize error messages to non-English languages, and many error messages end up sounding more kludgey than they could because of the "first word being an attribute name" restriction.

We're not addressing the entire issue with this patch - the Errors object isn't flexible enough to customize the format, as the only information we can pass per error is an attribute/string message combo.

What we did do is change the format of :message to accept a full sentence with string substitution for the symbol ":attribute". So, instead of

object.errors.add(:first_name, "can't be blank")

you could do

object.errors.add(:first_name, ":attribute can't be blank")

or

object.errors.add(:first_name, "Why are you making your :attribute blank?")

or

object.errors.add(:first_name, "People who don't change their name prefix are bad people.")

The :message parameter in validations work similarly. All default messages yield the same sentences as before.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages