在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的错误吗?
答案 0 :(得分:4)
使用/作为名称空间
activemodel:
errors:
models:
conversation/message:
attributes:
quantity:
blank: "Some custom message"