ActiveRecord error messages: translation for fields

不问归期 提交于 2019-12-03 15:11:22
eremite

You need to namespace your attributes under user, i.e.:

pt_br:
  activerecord:
    attributes:
      user:
        name: "Nome"
        address: "Endereço"

You can also install the i18n_label plugin to automatically translate the labels.

You can try <%= f.label :name, t('activerecord.attributes.name') %>.

What about human_attribute_name? Is there since Rails 2.1.0.

I think it's better then any other solutions:

<%= f.label :name, User.human_attribute_name(:name) %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!