# More questions: human\_name

**URL:** <https://www.ruby-forum.com/t/more-questions-human-name/95447>\
**Category:** Rails\
**Created:** [June 1, 2006, 3:28pm UTC](https://www.ruby-forum.com/t/more-questions-human-name/95447 "2006-06-01T15:28:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ymartin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/779978/32.png) [@ymartin](https://www.ruby-forum.com/u/ymartin)\
**Post date:** [June 1, 2006, 3:28pm UTC](https://www.ruby-forum.com/t/more-questions-human-name/95447/1 "2006-06-01T15:28:45Z")

</div>

One more question:

Is there some way to set the human\_name of a column? e.g.: human\_name  
for column address1 shouldn’t be Address1 but “Address, line 1”.

If not, should I make a hash with my custom names?

Best regards,

## –

Yannick M. [http://www.inma.ucl.ac.be/~majoros](http://www.inma.ucl.ac.be/~majoros)  
Informaticien UCL/INMA-MEMA  
4, avenue G. LemaÃ®tre  
B-1348 Louvain-la-Neuve  
Belgium  
Tel: +32-10-47.80.10  
Fax: +32-10-47.21.80  
Si vous avez des problÃ¨mes pour afficher ce message (accents qui ne  
passent pas, signature Ã©lectronique, …) votre systÃ¨me de mail n’est  
pas conforme aux standards modernes, voir  
[http://www.inma.ucl.ac.be/~majoros/email.html](http://www.inma.ucl.ac.be/~majoros/email.html)  
#JAPH : [Mathematical engineering (INMA) | UCLouvain](http://www.inma.ucl.ac.be/~majoros/japh.txt)

---

<div class="post-metadata">

**Author:** ![ymartin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/779978/32.png) [@ymartin](https://www.ruby-forum.com/u/ymartin)\
**Post date:** [June 2, 2006, 3:02am UTC](https://www.ruby-forum.com/t/more-questions-human-name/95447/2 "2006-06-02T03:02:53Z")

</div>

ActiveRecord uses the humanize method from the Inflector module in  
ActiveSupport to convert column names to human readable form. (See  
[http://rails.outertrack.com/module/Inflector/humanize](http://rails.outertrack.com/module/Inflector/humanize)) You can  
potentially override this method something like this:

module Inflector  
def humanize\_with\_fixes(name)  
case name  
when ‘address1’  
‘Address line 1’  
else  
humanize\_without\_fixes(name)  
end  
end

```
 alias_method :humanize_without_fixes, :humanize
 alias_method :humanize, :humanize_with_fixes

```

end

I’m not sure if this is the recommended approach, but it should work.  
It might be easier to just rename your column to address\_line\_1!

(Note that ActiveRecord also has a human\_attribute\_name method you  
could override for the same purpose, but source code comments  
indicate that this method is deprecated and that ActiveRecord may  
call the Inflector directly.)

Cheers,

Pete Y.  
[http://9cays.com/](http://9cays.com/)

---

<div class="post-metadata">

**Author:** ![ymartin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/779978/32.png) [@ymartin](https://www.ruby-forum.com/u/ymartin)\
**Post date:** [June 2, 2006, 5:05am UTC](https://www.ruby-forum.com/t/more-questions-human-name/95447/3 "2006-06-02T05:05:29Z")

</div>

> You can potentially override this method something like this

That seems slightly icky, (where is that code going to go?) but I  
can’t think of anything better at present. How are these custom names  
going to be used?

But also! You can change this

alias\_method :humanize\_without\_fixes, :humanize  
alias\_method :humanize, :humanize\_with\_fixes

to this

alias\_method\_chain :humanize, :fixes

as shown here

[http://weblog.rubyonrails.org/articles/2006/04/26/new-in-rails-](http://weblog.rubyonrails.org/articles/2006/04/26/new-in-rails-)  
module-alias\_method\_chain

–  
Michael D.  
[http://www.mdaines.com](http://www.mdaines.com)

---

<div class="post-metadata">

**Author:** ![ymartin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/779978/32.png) [@ymartin](https://www.ruby-forum.com/u/ymartin)\
**Post date:** [June 2, 2006, 3:21pm UTC](https://www.ruby-forum.com/t/more-questions-human-name/95447/4 "2006-06-02T15:21:05Z")

</div>

On 02/06/2006, at 1:03 PM, Michael D. wrote:

> > You can potentially override this method something like this
> 
> That seems slightly icky, (where is that code going to go?) but I  
> can’t think of anything better at present.

I never said it was a nice solution. 🙂

> [http://weblog.rubyonrails.org/articles/2006/04/26/new-in-rails-](http://weblog.rubyonrails.org/articles/2006/04/26/new-in-rails-)  
> module-alias\_method\_chain

Nice. I hadn’t come across that before.

Cheers,

Pete Y.  
[http://9cays.com](http://9cays.com)
