Rails 3 ActiveModel 嵌套类 I18n

发布于 2024-09-01 12:06:51 字数 1002 浏览 4 评论 0原文

给定 ruby​​ 中的以下类定义:

class Conversation
  class Message
    include ActiveModel::Validations
    attr_accessor :quantity
    validates :quantity, :presence => true
  end
end

How can you use i18n to customize to error message。 例如,Conversation 类的正确查找应该是

activemodel:
  errors:
    models:
      conversation:
        attributes:
          quantity:
            blank: "Some custom message"

但是 Message 类的它是什么? 我尝试过:

activemodel:
  errors:
    models:
      conversation:
        message:
          attributes:
            quantity:
              blank: "Some custom message"

activemodel:
  errors:
    models:
      message:
        attributes:
          quantity:
            blank: "Some custom message"

activemodel:
  errors:
    models:
      conversation::message:
        attributes:
          quantity:
            blank: "Some custom message"

没有一个有效 有什么想法或者这是 ActiveModel 或 I18n 的错误吗?

Given the following class definition in ruby:

class Conversation
  class Message
    include ActiveModel::Validations
    attr_accessor :quantity
    validates :quantity, :presence => true
  end
end

How can you use i18n to customize to error message.
For example the correct lookup for the class Conversation would be

activemodel:
  errors:
    models:
      conversation:
        attributes:
          quantity:
            blank: "Some custom message"

But what is it for the Message class?
I tried:

activemodel:
  errors:
    models:
      conversation:
        message:
          attributes:
            quantity:
              blank: "Some custom message"

activemodel:
  errors:
    models:
      message:
        attributes:
          quantity:
            blank: "Some custom message"

activemodel:
  errors:
    models:
      conversation::message:
        attributes:
          quantity:
            blank: "Some custom message"

None of them work
Any ideas or is this a bug with ActiveModel or I18n?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她比我温柔 2024-09-08 12:06:51

使用 / 表示命名空间

activemodel:
  errors:
    models:
      conversation/message:
        attributes:
          quantity:
            blank: "Some custom message"

Use a / for namespaces

activemodel:
  errors:
    models:
      conversation/message:
        attributes:
          quantity:
            blank: "Some custom message"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文