Examples:
<%=
form_for :delivery, routes.deliveries_path do
text_field :customer_name
fields_for_collection :addresses do
text_field :street
end
submit 'Create'
end
%>
<!-- output -->
<form action="/deliveries" method="POST" accept-charset="utf-8" id="delivery-form">
<input type="hidden" name="_csrf_token" value="920cd5bfaecc6e58368950e790f2f7b4e5561eeeab230aa1b7de1b1f40ea7d5d">
<input type="text" name="delivery[customer_name]" id="delivery-customer-name" value="">
<input type="text" name="delivery[addresses][][street]" id="delivery-address-0-street" value="">
<input type="text" name="delivery[addresses][][street]" id="delivery-address-1-street" value="">
<button type="submit">Create</button>
</form>
<%=
form_for(:bill, routes.bill_path(id: bill.id), { bill: bill }, method: :patch, class: 'form-horizontal') do
fieldset do
legend "Addresses"
fields_for_collection :addresses do |i, address|
div class: "form-group" do
text "Address id: #{address.id}"
label :street
input_text :street, class: "form-control", placeholder: "Street", "data-funky": "index-#{i}"
end
end
label :ensure_names
end
submit submit_label, class: "btn btn-default"
end
%>
<!-- output -->
<form action="/bills/1" method="POST" accept-charset="utf-8" id="bill-form" class="form-horizontal">
<input type="hidden" name="_method" value="PATCH">
<input type="hidden" name="_csrf_token" value="920cd5bfaecc6e58368950e790f2f7b4e5561eeeab230aa1b7de1b1f40ea7d5d">
<fieldset>
<legend>Addresses</legend>
<div class="form-group">
Address id: 23
<label for="bill-addresses-0-street">Street</label>
<input type="text" name="bill[addresses][][street]" id="bill-addresses-0-street" value="5th Ave" class="form-control" placeholder="Street" data-funky="index-0">
</div>
<div class="form-group">
Address id: 42
<label for="bill-addresses-1-street">Street</label>
<input type="text" name="bill[addresses][][street]" id="bill-addresses-1-street" value="4th Ave" class="form-control" placeholder="Street" data-funky="index-1">
</div>
<label for="bill-ensure-names">Ensure names</label>
</fieldset>
<button type="submit" class="btn btn-default">Update</button>
</form>