Schienen 4 +Summe von tief verschachtelten Form Attribute
Ein wenig Hintergrund Kokon:
orders has_many order_products
order_products has_many product_sizes
In einem after_save Anruf würde ich die Gesamtmenge aller Produkte erhalten möchte. Ich habe eine Datenbankspalte mit der Bezeichnung total_qty
im Modell order_product
. Also in diesem Bild würde die Gesamt 37.
Bestellformular
= f.simple_fields_for :order_products do |order_product|
= render 'order_product_fields', :f => order_product
= link_to_add_association 'Add Product', f, :order_products
order_product_fields sein
= f.simple_fields_for :product_sizes do |product_size|
= render 'product_size_fields', :f => product_size
= link_to_add_association 'Add Size', f, :product_sizes
product_size_fields
<div class="row nested-fields">
= f.input :size_name, :collection => Order::SIZES, label: false, include_blank: false
= f.input :qty, label: false, class: "<%= product_sizes.index %>"
= link_to_remove_association f, class: 'btn btn-danger' do
.glyphicon.glyphicon-remove
</div>