I have a complex nested form which takes a few seconds to load when it's not cached. The hidden id fields look like this:
<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]">
Now I want to cache parts of the form and only change the parts that are updated. The problem is that fields_for
doesn't recognize the cached parts and starts the counter at 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>
So the second [0][id]-field overrides the first one.
Is there a way to use random strings and not sequential integers like this?
<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]">
Then the cached fields could stay the same without any interference. Thanks for any ideas how to solve this!
I eventually solved it with JavaScript.