Closed zuburqan closed 4 years ago
Alrighty, I found the problem. The issue was that using simple_fields_for (of simple_form gem) inserts the hidden input field containing the id in between the tbody and the tr.
Datatables remove any such input html element either because it is invalid HTML as per https://validator.w3.org/ or because it is hidden.
Solution was to place a hidden field for id manually in the td and then datatables does not take that out and hence you get the id field back.
Background: I am using simple_form to render nested attributes of an association in rails. I have applied jquery-datatables gem on the edit form for the nested association using simple_fields_for.
My model is:
My view is:
edit.html.slim
_foo_fields.html.slim
controller
Javascript
Problem: With the above, the id field in the nested association disappears from the params. Without datatables applied it reappears. This causes rails to create new fields rather than updating the existing ones with datatables enabled.
params without datatables
params with datatables (no id field present)
Note: I am allowing all the attributes in the params for the nested association, so its not an issue about params permit.