gpt4 book ai didi

ruby-on-rails - Rails 3 ActiveModel 嵌套类 I18n

转载 作者:行者123 更新时间:2023-12-04 06:08:25 25 4
gpt4 key购买 nike

给定以下 ruby​​ 类定义:

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

如何使用 i18n 自定义错误消息。例如,类 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 的错误?

最佳答案

使用/作为命名空间

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

关于ruby-on-rails - Rails 3 ActiveModel 嵌套类 I18n,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2840834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com