Rails 3 ActiveModel嵌套类I18n

时间:2010-05-15 16:22:57

标签: ruby-on-rails internationalization nested-class activemodel

在ruby中给出以下类定义:

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

如何使用i18n自定义错误信息。 例如,对话类的正确查找将是

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的错误吗?

1 个答案:

答案 0 :(得分:4)

使用/作为名称空间

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