1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<% form_for( @garage ) do |f| %>

<p>
  <%= f.label :name %>
  <%= f.text_field :name %>
</p>

<% @garage.vehicles.each_with_index { |vehicle, index| %>
  <% vehicle_type = "#{ ((vehicle.new_record?)? "new_vehicles : "existing_vehicles") }" -%>
  <% vehicle_id = (!vehicle.new_record?)? vehicle.id : index -%>

  <% f.fields_for "#{vehicle_type}[]", vehicle, :index => vehicle_id do |vehicle_f| -%>
  <p>
    <%= vehicle_f.label :name %>
    <%= vehicle_f.text_field :name %>
  </p>
  <p>
    <%= vehicle_f.label :delete %>
    <%= vehicle_f.check_box :delete %>
  </p>
  <% end -%>
<% } %>


<% end %>