app/views/shared/partials/_contacts_form.html.erb
<% sections ||= ["header", "button"] %>
<% headline ||= "Ansprechpartner" %>
<% fields = ["first_name", "last_name", "email", "phone", "fax", "web_urls"] %>
<% force_visibility ||= false %>
<% list_of_contacts = record.contacts.presence || [OpenStruct.new] %>
<div class="row">
<div class="col">
<h3 class="d-sm-flex align-items-center justify-content-between my-4">
<%= headline %>
</h3>
</div>
</div>
<div id="nested-contacts">
<% list_of_contacts.each_with_index do |contact, index| %>
<%= form.fields_for "contacts[#{index}]", contact do |fc| %>
<div class="nested-contact-form<%= " d-none" if !force_visibility && empty?(contact, fields) %>">
<div class="card mb-4">
<% if sections.include?("header") %>
<div class="d-flex flex-wrap justify-content-between card-header py-3 bg-dark text-white">
<h4>
Kontakt
</h4>
<%= link_to "#", class: "remove btn btn-sm btn-danger" do %>
<i class="fa fa-trash text-white"></i>
<% end %>
</div>
<% end %>
<div class="card-body">
<%= render partial: "shared/partials/contact_form", locals: { form: fc, contact: contact } %>
</div>
</div>
</div>
<% end %>
<% end %>
</div>
<% if sections.include?("button") %>
<%= link_to "#", class: "btn btn-sm btn-secondary", id: "nested-add-contacts" do %>
<i class="fas fa-plus text-white mr-2"></i>
Kontakt hinzufügen
<% end %>
<% end %>