Change column name in view

Pål Bergström wrote:

How can I change the column name from the db so it's displayed in view
in a different way?

Your question is unclear as stated. Can you provide more context?

Best,

Pål Bergström wrote:
[...]

The column name in the db is 'email'. I would like that to be displayed
in Swedish like 'E-post'.

And what's your view file like?

Best,

Marnen Laibow-Koser wrote:

Pål Bergström wrote:
[...]

The column name in the db is 'email'. I would like that to be displayed
in Swedish like 'E-post'.

And what's your view file like?

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org

I mean in an error_messages_for. Sorry.

Are you using Rails 2.2 or 2.3? In these versions, you could use the
I18n library (editing the .yml on the config/locales directory):

activerecord:
    attributes:
      <model_name>:
        <field>: <translated_name>

You could put this in your model (the one that maps to the table with
the email column) if you don't need to use the internationalisation
capabilities:

HUMAN_ATTRIBUTES = {:email => 'E-post'}
def self.human_attribute_name(attr)
  HUMAN_ATTRIBUTES[attr.to_sym] || super
end

Note that you can rename more than one column:
HUMAN_ATTRIBUTES = {:email => 'E-post', :some_other_column => 'Another
name'}

Chris Bartlett wrote:

HUMAN_ATTRIBUTES = {:email => 'E-post'}
def self.human_attribute_name(attr)
  HUMAN_ATTRIBUTES[attr.to_sym] || super
end

Note that you can rename more than one column:
HUMAN_ATTRIBUTES = {:email => 'E-post', :some_other_column => 'Another
name'}

Great. Works perfect.