method

human_attribute_name

human_attribute_name(attribute, options = {})
public

Transforms attribute names into a more human format, such as "First name" instead of "first_name".

  Person.human_attribute_name("first_name") # => "First name"

Specify options with additional translating options.

3Notes

I18n file to change an attribute's name

andmej · Dec 11, 20102 thanks

If you are using Active Record, use a locale file like the one below to change a model's attribute's human name.

en:
activerecord:
  attributes:
    picture:
      explanation: Description

Without using the locale file:

ruby-1.9.2-p0 > Picture.human_attribute_name("explanation")

=> "Explanation"

Using the locale file:

ruby-1.9.2-p0 > Picture.human_attribute_name("explanation")

=> "Description"

Default values

Alex2222 · Jun 29, 20112 thanks

For common attributes in several models, you can set a default human name like this:

==== de.yml

de:
attributes:
  bez: Bezeichnung
  abk: Abkürzung

Works also with Mongoid

josh · Jan 29, 2013

What works for Active Record, also works for Mongoid:

de:
mongoid:
  attributes:
    picture:
      explanation: Description