Rails nested form new association -
i creating form nested attributes. relevant parts there sale
model (the master model form), vehicle
model (sale has_one vehicle , vehicle belongs_to sale), , registration_number
model (many many vehicles, through assignment table).
i using excellent flexbox jquery plugin, allows existing item selected or new item created.
because working flexbox, fields in question being coded largely in html, bypassing rails helpers.
when attempt create new registration number (using field name sale[vehicle_attributes][registration_numbers_attributes][0][number]
), works great, new registration number created , assigned vehicle. when try assign existing registration number (using field name sale[vehicle_attributes][registration_numbers_attributes][id]
), however, following error:
couldn't find registrationnumber id=3 vehicle id=5
this doesn't seem make lot of sense - way see it, rails should trying create association, not find existing association? ideas might doing wrong?
thanks!
you achieve manipulating intermediate table, here assignment
.
insert in model:
accepts_nested_attributes_for :assignments
and in html, append line:
<input name="sale[vehicle_attributes][assignments_attributes][0][registration_number_id]" value="the_registration_number_id_goes_here" type="hidden">
Comments
Post a Comment