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!


Regards,

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

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. <

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

Regards,
Luiz Vitor

On Sat, Jul 19, 2008 at 2:59 PM, AnnaLissa C. [email protected]
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
engineer student at maua.br

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. <

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. [email protected]

On Jul 19, 8:50 pm, “AnnaLissa C.” [email protected] 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) 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