How can I change the column name from the db so it’s displayed in view
in a different way?
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,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Marnen Laibow-Koser wrote:
Pål Bergström wrote:
Your question is unclear as stated. Can you provide more context?
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
The column name in the db is ‘email’. I would like that to be displayed
in Swedish like ‘E-post’.
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
[email protected]
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
[email protected]
I mean in an error_messages_for. Sorry.
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’}
On Oct 17, 10:31 am, Pål Bergström [email protected]
Chris B. wrote:
HUMAN_ATTRIBUTES = {:email => ‘E-post’}
def self.human_attribute_name(attr)
HUMAN_ATTRIBUTES[attr.to_sym] || super
endNote that you can rename more than one column:
HUMAN_ATTRIBUTES = {:email => ‘E-post’, :some_other_column => ‘Another
name’}
Great. Works perfect.
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>:
: <translated_name>
On Oct 16, 6:31 pm, Pål Bergström [email protected]