I have a model called User with an attribute called current_sign_in_at. In my en.yml file I have the display name as such…
en-GB:
activerecord:
attributes:
user:
current_sign_in_at: "Last sign-in"
…which allows me to display the desired form label (“Last sign-in”) using = f.label :current_sign_in_at.
But how can I use this same translation for a table header, i.e. not in a form?
%th= :current_sign_in_at
You can use the static method “human_attribute_name”, See the doc here on API dock
In your case:
(use
User.human_nameto display the model name translated with I18n inen.activerecord.models.user)Hope this helps!