Rails 3 ActiveModel Nested Class 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 the error message. For example, the correct search for the conversation class will be

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

But what is this 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?

+3
source share
1 answer

Use namespaces for /

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

Source: https://habr.com/ru/post/1745577/


All Articles