Rails 7 中是否可以本地化表单对象中的属性,包括
ActiveModel::Model
?
我有以下内容
class ProductionDataForm
include ActiveModel::Model
attr_accessor :monitorable_type
validates :monitorable_type, presence: true
end
当
monitorable_type
丢失时,我想显示 Post can't be blank
而不是 Monitorable type can't be blank
。
因此,正如我对继承自
ApplicationRecord
的对象所做的那样,我尝试定义
en:
activerecord:
attributes:
production_data_form:
monitorable_type: "post"
但是不起作用。
class ProductionDataForm
include ActiveModel::Model
include ActiveModel::Attributes
attribute :monitorable_type, :string # ?
validates :monitorable_type, presence: true
end
en:
activemodel:
attributes:
production_data_form:
monitorable_type: "post"