【问题标题】:Rails: Partly caching a nested formRails:部分缓存嵌套表单
【发布时间】:2017-06-02 04:57:11
【问题描述】:

我有一个复杂的嵌套表单,当它没有被缓存时加载需要几秒钟。隐藏的 id 字段如下所示:

<input type="hidden" value="1" name="user[properties_attributes][0][id]">
<input type="hidden" value="2" name="user[properties_attributes][1][id]">
<input type="hidden" value="3" name="user[properties_attributes][2][id]">
<input type="hidden" value="4" name="user[properties_attributes][3][id]">

现在我想缓存部分表单,只更改更新的部分。问题是fields_for 无法识别缓存的部分并从0开始计数器:

<cached>
  <input type="hidden" value="1" name="user[properties_attributes][0][id]">
  <input type="hidden" value="2" name="user[properties_attributes][1][id]">
</cached>
<updated>
  <input type="hidden" value="3" name="user[properties_attributes][0][id]">
</updated>
<cached>
  <input type="hidden" value="4" name="user[properties_attributes][3][id]">
</cached>

所以第二个 [0][id] 字段会覆盖第一个。

有没有办法使用随机字符串而不是像这样的连续整数?

<input type="hidden" value="1" name="user[properties_attributes][ab2ca3ga][id]">
<input type="hidden" value="2" name="user[properties_attributes][d7e555wf][id]">
<input type="hidden" value="3" name="user[properties_attributes][g18fhhd1][id]">
<input type="hidden" value="4" name="user[properties_attributes][jl8h18dh][id]">

然后缓存的字段可以保持不变而不受任何干扰。 感谢您提供解决此问题的任何想法!

【问题讨论】:

    标签: ruby-on-rails forms caching fields-for russian-doll-caching


    【解决方案1】:

    我最终用 JavaScript 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多