【发布时间】:2020-02-18 07:12:23
【问题描述】:
Rails 5 使用(嵌套属性上的错误索引)为模型添加错误索引:
class Order
has_many :operations, index_errors: true
accepts_nested_attributes_for :operations
end
class Operation
has_many :inv_items, index_errors: true
accepts_nested_attributes_for :inv_items
end
由于调用 order.errors.full_messages 我收到这种形式的错误:
{:"operations[0].inv_items[0].serial_num"=>["不能为空"], :"operations[0].inv_items[1].serial_num"=>[ "不能为空"]}
在.yml文件中我可以直接设置翻译
en:
activerecord:
attributes:
warehouse/order/operations[0]/inv_items[0]:
serial_num: 'Serial number'
但是如何在不标明每个索引的情况下组织翻译呢?
【问题讨论】:
-
嗨,我也有同样的问题。您找到任何解决方法了吗?
标签: ruby-on-rails activerecord indexing message rails-i18n