ryanb / nested_form

Rails plugin to conveniently handle multiple models in a single form.
MIT License
1.79k stars 505 forks source link

Fix id generation if parent has no input #266

Closed kirel closed 11 years ago

kirel commented 11 years ago

If the parent form had no inputs

var context = ($(link).closest('.fields').closestChild('input, textarea, select').eq(0).attr('name') || '').replace(/\[[a-z_]+\]$/, '');

would have picked up too much. The subsequent loop would have replaced the [some_attributes][new_assoc]-part with [some_attributes][1] (or whetever id was present).

This pull request works around that case by stripping the context accordingly.

Specs still pass but I haven't added any new ones.

lest commented 11 years ago

Thanks!