method
human_attribute_name
![Wide documentation Importance_3](https://d2vfyqvduarcvs.cloudfront.net/images/importance_3.png?1349367920)
Ruby on Rails latest stable (v7.1.3.2)
-
4 notes -
Class: ActiveModel::Translation
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (-38)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
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.
Register or
log in
to add new notes.
andmej -
December 11, 2010 - (v3.0.0)
Alex2222 -
June 29, 2011
josh -
January 29, 2013
shadow11 -
July 18, 2013 - (v3.2.1 - v3.2.13)
![Default_avatar_30](https://www.gravatar.com/avatar/7e565a1681dc0137f43826aa840686af?default=http://apidock.com/images/default_avatar_30.png&size=30)
2 thanks
I18n file to change an attribute's name
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_avatar_30](https://www.gravatar.com/avatar/c0b00b675384d94c0daaa0a65e46b2e8?default=http://apidock.com/images/default_avatar_30.png&size=30)
2 thanks
Default values
For common attributes in several models, you can set a default human name like this:
de.yml
de: attributes: bez: Bezeichnung abk: Abkürzung
![Default_avatar_30](https://www.gravatar.com/avatar/fc582698581884352e745d1d4c64699d?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
Works also with Mongoid
What works for Active Record, also works for Mongoid:
de: mongoid: attributes: picture: explanation: Description
![Default_avatar_30](https://www.gravatar.com/avatar/679c1174a6384d1b73f643cd9b8c2b2e?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
Nested i18n attributes
If you want to use nested attributes in a i18n file (like person :has_many => :addresses), write:
en: activerecord: attributes: person: name: "person/addresses": street: "Street name" "person/phones": area: "Area code" number: Number