# Change column name in view

**URL:** <https://www.ruby-forum.com/t/change-column-name-in-view/177428>\
**Category:** Rails\
**Created:** [October 16, 2009, 10:53pm UTC](https://www.ruby-forum.com/t/change-column-name-in-view/177428 "2009-10-16T22:53:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [October 16, 2009, 10:53pm UTC](https://www.ruby-forum.com/t/change-column-name-in-view/177428/1 "2009-10-16T22:53:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [October 16, 2009, 11:19pm UTC](https://www.ruby-forum.com/t/change-column-name-in-view/177428/2 "2009-10-16T23:19:49Z")

</div>

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](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [October 16, 2009, 11:22pm UTC](https://www.ruby-forum.com/t/change-column-name-in-view/177428/3 "2009-10-16T23:22:45Z")

</div>

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](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

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

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [October 16, 2009, 11:29pm UTC](https://www.ruby-forum.com/t/change-column-name-in-view/177428/4 "2009-10-16T23:29:12Z")

</div>

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](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [October 16, 2009, 11:31pm UTC](https://www.ruby-forum.com/t/change-column-name-in-view/177428/5 "2009-10-16T23:31:58Z")

</div>

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](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

I mean in an error\_messages\_for. Sorry.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [October 17, 2009, 10:43am UTC](https://www.ruby-forum.com/t/change-column-name-in-view/177428/6 "2009-10-17T10:43:28Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [October 17, 2009, 7:47pm UTC](https://www.ruby-forum.com/t/change-column-name-in-view/177428/7 "2009-10-17T19:47:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [October 17, 2009, 7:54am UTC](https://www.ruby-forum.com/t/change-column-name-in-view/177428/8 "2009-10-17T07:54:20Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
