# Aliasing field names in validators

**URL:** <https://www.ruby-forum.com/t/aliasing-field-names-in-validators/117142>\
**Category:** Rails\
**Created:** [October 13, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/aliasing-field-names-in-validators/117142 "2007-10-13T20:07:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jemminger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@jemminger](https://www.ruby-forum.com/u/jemminger)\
**Post date:** [October 13, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/aliasing-field-names-in-validators/117142/1 "2007-10-13T20:07:17Z")

</div>

suppose i have a model:

class Foo  
belongs\_to :some\_customized\_bar  
validates\_presence\_of :some\_customized\_bar\_id  
end

if i use ‘error\_messages\_for :foo’ in a view, i’ll get errors like:  
“Some customized bar can’t be blank”

is it possible to tell the validator to use another name for that  
field, or do i have to do it myself using the model.errors collection?

thanks,  
jeff

---

<div class="post-metadata">

**Author:** ![jemminger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@jemminger](https://www.ruby-forum.com/u/jemminger)\
**Post date:** [October 13, 2007, 10:57pm UTC](https://www.ruby-forum.com/t/aliasing-field-names-in-validators/117142/2 "2007-10-13T22:57:01Z")

</div>

> validates\_presence\_of :some\_customized\_bar\_id, :message =\> “RubyonRails  
> is Awesome”

Jamal – I’m not sure this answered Jeff’s question, which involved  
setting another name for the _field_, I believe. Adding the :message  
parameter only affects what’s after the field name, so when a form is  
validated, the \<%= error\_messages\_for ‘widget’ %\> results in text like

“Some customized bar RubyonRails is Awesome”

Is there a way to also change the field name (or not have it show up  
at all?)

Thanks Jamal, and thanks Jeff for asking the question 🙂

Tom

---

<div class="post-metadata">

**Author:** ![jemminger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@jemminger](https://www.ruby-forum.com/u/jemminger)\
**Post date:** [October 13, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/aliasing-field-names-in-validators/117142/3 "2007-10-13T21:23:25Z")

</div>

Jeff Emminger wrote:

> suppose i have a model:
> 
> class Foo  
> belongs\_to :some\_customized\_bar  
> validates\_presence\_of :some\_customized\_bar\_id  
> end
> 
> if i use ‘error\_messages\_for :foo’ in a view, i’ll get errors like:  
> “Some customized bar can’t be blank”
> 
> is it possible to tell the validator to use another name for that  
> field, or do i have to do it myself using the model.errors collection?
> 
> thanks,  
> jeff

validates\_presence\_of :some\_customized\_bar\_id, :message =\> “RubyonRails  
is Awesome”
