I am having difficulty understanding the way to layout the view to have the properties nest properly for a nested form.
My params look like this...
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"retsty/G2I1FyYybXm9kVaZi+aPjQm4jsmLdLW3wxsc=",
"receipt"=>{"receipt"=>"", "receipt_date(1i)"=>"2014", "receipt_date(2i)"=>"9", "receipt_date(3i)"=>"19",
"po_receipts_attributes"=>[
{"jobquote_order_id"=>{"3"=>"", "5"=>""}, "qty"=>"30"},
{"qty"=>"11"}
]},
"commit"=>"Receive"}
The po_receipts_attributes array is not nesting the hash correctly.
Format: po_receipts_attributes: [{jobquote_order_id: <value>, qty: <value>}, {jobquote_order_id: <value>, qty: <value>}]
According to http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html, my params should look like this...
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"retsty/G2I1FyYybXm9kVaZi+aPjQm4jsmLdLW3wxsc=",
"receipt"=>{"receipt"=>"", "receipt_date(1i)"=>"2014", "receipt_date(2i)"=>"9", "receipt_date(3i)"=>"19",
"po_receipts_attributes"=>[
{"jobquote_order_id"=>"3", "qty"=>"30"},
{"jobquote_order_id"=>"5", "qty"=>"11"}
]},
"commit"=>"Receive"}
I can't seem to get the way to nest an attributes correctly in the view. I have tried many different syntaxes for this.
In my view I have the following code...
= hidden_field "receipt[po_receipts_attributes][][jobquote_order_id]", jq_o.id
= text_field_tag "receipt[po_receipts_attributes][][qty]", ""
HTML output...
<td>
<input id="receipt_po_receipts_attributes__jobquote_order_id_3" name="receipt[po_receipts_attributes][][jobquote_order_id][3]" type="hidden" />
<input id="receipt_po_receipts_attributes__qty" name="receipt[po_receipts_attributes][][qty]" type="text" value="" />
</td>
<td>
<input id="receipt_po_receipts_attributes__jobquote_order_id_5" name="receipt[po_receipts_attributes][][jobquote_order_id][5]" type="hidden" />
<input id="receipt_po_receipts_attributes__qty" name="receipt[po_receipts_attributes][][qty]" type="text" value="" />
</td>
What would be the best way to handle this?