# How to alias the columns names to change the name on error\_messages\_for?

**URL:** <https://www.ruby-forum.com/t/how-to-alias-the-columns-names-to-change-the-name-on-error-messages-for/143506>\
**Category:** Rails\
**Created:** [July 19, 2008, 5:29pm UTC](https://www.ruby-forum.com/t/how-to-alias-the-columns-names-to-change-the-name-on-error-messages-for/143506 "2008-07-19T17:29:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [July 19, 2008, 5:29pm UTC](https://www.ruby-forum.com/t/how-to-alias-the-columns-names-to-change-the-name-on-error-messages-for/143506/1 "2008-07-19T17:29:43Z")

</div>

Yeah,

How can i alias the columns names to show another string name in  
error\_messages\_for?

class CreateUsers \< ActiveRecord::Migration  
def self.up  
create\_table :users do |t|  
t.column :pizza, :string

I want to show ‘salame’

Thanks for your attention!

–  
Regards,

Luiz Vitor Martinez C.  
cel.: (11) 8187-8662  
blog: [rubz.org](http://rubz.org)  
engineer student at maua.br

---

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [July 19, 2008, 6:32pm UTC](https://www.ruby-forum.com/t/how-to-alias-the-columns-names-to-change-the-name-on-error-messages-for/143506/2 "2008-07-19T18:32:24Z")

</div>

This is what I have done in the past, but it may not be the best  
solution.  
In your user model…

class User \< ActiveRecord::Base

def beautifunction  
{ :pizza =\> ‘salame’ }  
end

def self.human\_attribute\_name(s)  
beautifunction[s.to\_sym] || super(s)  
end

end

Best regards.  
Anna Lissa

On Sat, Jul 19, 2008 at 8:28 AM, Luiz Vitor Martinez C. \<

---

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [July 19, 2008, 8:11pm UTC](https://www.ruby-forum.com/t/how-to-alias-the-columns-names-to-change-the-name-on-error-messages-for/143506/3 "2008-07-19T20:11:53Z")

</div>

Thanks! This really works. But what’s the Rails way?

Regards,  
Luiz Vitor

On Sat, Jul 19, 2008 at 2:59 PM, AnnaLissa C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > This is what I have done in the past, but it may not be the best  
> > end
> > 
> > > Yeah,
> 
> >

–  
Regards,

Luiz Vitor Martinez C.  
cel.: (11) 8187-8662  
blog: [rubz.org](http://rubz.org)  
engineer student at maua.br

---

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [July 19, 2008, 9:50pm UTC](https://www.ruby-forum.com/t/how-to-alias-the-columns-names-to-change-the-name-on-error-messages-for/143506/4 "2008-07-19T21:50:47Z")

</div>

That’s a good question. As far as I can tell, there is no Rails way to  
do  
this as of Rails 2.0.2. I spent some time reviewing how  
error\_messages\_for  
works and then came up with this solution. I would love to know if 2.1  
addresses the problem, or if we’re really looking at a documentation  
problem.

Regards,  
Anna Lissa

On Sat, Jul 19, 2008 at 11:11 AM, Luiz Vitor Martinez C. \<

---

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [July 19, 2008, 7:59pm UTC](https://www.ruby-forum.com/t/how-to-alias-the-columns-names-to-change-the-name-on-error-messages-for/143506/5 "2008-07-19T19:59:36Z")

</div>

one correction to my solution:

use self.beautifunction (should be a class method not an instance  
method)

– Anna Lissa

On Sat, Jul 19, 2008 at 9:32 AM, AnnaLissa C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [July 20, 2008, 2:49pm UTC](https://www.ruby-forum.com/t/how-to-alias-the-columns-names-to-change-the-name-on-error-messages-for/143506/6 "2008-07-20T14:49:38Z")

</div>

On Jul 19, 8:50 pm, “AnnaLissa C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> That’s a good question. As far as I can tell, there is no Rails way to do  
> this as of Rails 2.0.2. I spent some time reviewing how error\_messages\_for  
> works and then came up with this solution. I would love to know if 2.1  
> addresses the problem, or if we’re really looking at a documentation  
> problem.

I use the Human Attribute Override plugin (http://  
[agilewebdevelopment.com/plugins/human\_attribute\_override](http://agilewebdevelopment.com/plugins/human_attribute_override)) with Rails  
2.0 which essentially does the same thing as your earlier example.

Just committed this month is a patch ([http://rails.lighthouseapp.com/](http://rails.lighthouseapp.com/)  
projects/8994/tickets/535-humanize-inflections) that allows you to  
specify particular results for the humanize string method. I think  
it’s a flawed approach because it is not unreasonable to have the same  
attribute name on different models but to want different display names  
and I as far as I can see it will not allow that.

Best regards,  
Andrew
