Rails 5使用(嵌套属性上的错误索引)为模型添加错误索引:
class Order
has_many :operations, index_errors: true
accepts_nested_attributes_for :operations
endclass Operation
has_many :inv_items, index_errors: true
accepts_nested_attributes_for :inv_items
end由于调用了order.errors.full_messages,我得到了以下形式的错误:
{:“operations.inv_items.serial_num”=>“不能为空”,“operations.inv_items1.serial_num”“=>”不能为空“}
在文件.yml中,我可以直接设置翻译
en:
activerecord:
attributes:
warehouse/order/operations[0]/inv_items[0]:
serial_num: 'Serial number'但是,如何组织翻译而不指明每个索引呢?
发布于 2020-02-18 09:41:37
尝试为模型设置翻译,而不将其嵌套在模型的关联中。就像下面的片段。
en:
activerecord:
models:
inv_item: Inventory Item
attributes:
inv_item:
serial_num: Serial Numberhttps://stackoverflow.com/questions/60275579
复制相似问题