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:
%th= User.human_attribute_name :current_sign_in_at
(use User.human_name
to display the model name translated with I18n in en.activerecord.models.user
)
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With