# Change error messages for Validation helpers?

**URL:** <https://www.ruby-forum.com/t/change-error-messages-for-validation-helpers/52621>\
**Category:** Rails\
**Created:** [January 17, 2006, 2:22am UTC](https://www.ruby-forum.com/t/change-error-messages-for-validation-helpers/52621 "2006-01-17T02:22:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@jeet](https://www.ruby-forum.com/u/jeet)\
**Post date:** [January 17, 2006, 2:22am UTC](https://www.ruby-forum.com/t/change-error-messages-for-validation-helpers/52621/1 "2006-01-17T02:22:24Z")

</div>

Is it possible to change error messages for Validation helpers? I am  
writing an app against a existing database (so no control over column  
names), but when there is validation error (e.g. with  
validate\_presence\_of) I would like to customize the field name. For  
example for telephone whose field name is PhoneNumber I would like to  
chnage it to “Telephone Number cannot be empty” rather than “Phonenumber  
cannot be empty”. Is that possible?

–Jeet

---

<div class="post-metadata">

**Author:** ![jeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@jeet](https://www.ruby-forum.com/u/jeet)\
**Post date:** [January 17, 2006, 3:04am UTC](https://www.ruby-forum.com/t/change-error-messages-for-validation-helpers/52621/2 "2006-01-17T03:04:33Z")

</div>

validates\_presence\_of :fld\_name, :message =\> “Telephone Number cannot  
be  
empty”  
should do it.

-bakki

---

<div class="post-metadata">

**Author:** ![jeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@jeet](https://www.ruby-forum.com/u/jeet)\
**Post date:** [January 17, 2006, 3:28am UTC](https://www.ruby-forum.com/t/change-error-messages-for-validation-helpers/52621/3 "2006-01-17T03:28:38Z")

</div>

On 1/16/06, Navjeet C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is it possible to change error messages for Validation helpers? I am  
> writing an app against a existing database (so no control over column  
> names), but when there is validation error (e.g. with  
> validate\_presence\_of) I would like to customize the field name. For  
> example for telephone whose field name is PhoneNumber I would like to  
> chnage it to “Telephone Number cannot be empty” rather than “Phonenumber  
> cannot be empty”. Is that possible?

If you have a limited number of them to override, you can do something  
like this, either in your environment.rb, or something that gets  
loaded automatically:

module Inflector  
alias\_method :humanize\_base, :humanize  
def self.humanize(word)  
return “Telephone Number” if word == ‘phonenumber’  
humanize\_base(word)  
end  
end

You could load up your custom ‘humanized’ attributes from a YAML file,  
if you wanted, and check against that list inside humanize.

If you have something more specific in mind, you’re better off making  
your own ‘error\_messages\_for’ helper. Check out the source for it in  
the API documentation. It’s quite simple, and is really only there as  
a scaffold.
