如何在I18n语言环境文件中指定模型之间的共享属性转换?

Zeq*_*uez 15 activerecord locale ruby-on-rails internationalization models

我尝试了以下方法:

es:
  activerecord:
    attributes:
      name: Nombre
Run Code Online (Sandbox Code Playgroud)

它没有用.

但以下工作:

es:
  activerecord:
    attributes:
      person:
        name: Nombre
Run Code Online (Sandbox Code Playgroud)

哪种方法可以跨模型定义默认属性?

我也在使用Formtastic和Active Admin.

Hal*_*gür 37

将共同点attributes向上移动一级:

es:
  attributes:
    name: Nombre
  activerecord:
    attributes:
      user:
        birthday: Etc
Run Code Online (Sandbox Code Playgroud)

  • 这应该是选定的答案. (4认同)

War*_*eto 9

这就是我在做的事情.不完美但会完成这项工作.

activerecord:
  attributes:
    attribute_commons: &commons
      name: Nome
      description: Descrição
    user:
      <<: *commons
    role:
      <<: *commons
      level: Nível
    product:
      <<: *commons
      size: Tamanho
Run Code Online (Sandbox Code Playgroud)

  • 答案如下:http://stackoverflow.com/a/30760306/650046是一个更好的答案. (2认同)