How to alias the columns names to change the name on error_messages_for ?

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!

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

one correction to my solution:

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

– Anna Lissa

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

Regards,
Luiz Vitor

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

I use the Human Attribute Override plugin (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/
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