Rails' fields_for
helper inserts a hidden ID field into your form. This is
generally helpful, because you'll want that information when you're updating
the record. But what if you don't?
This is the scenario I encountered today: a 'read-only' form nested inside a
fields_for
helper, with no inputs. It almost worked: unfortunately, due to
the default ID-inserting behavior of fields_for
, there was a hidden ID
input. It was getting submitted with the rest of the form and breaking things.
include_id: false
is the option we need.
<%= person_form.fields_for :projects, {}, include_id: false do |project_fields| %>
Project #<%= project_fields.index %>
<% end %>
With this option, no hidden ID will be inserted into the fields.