After spending time on my own decision, everything became crazy, as there is code spoiled and more lines of code.
For nested forms, I got this as a solution for me, since it also does not require interaction with the controller.
http://railscasts.com/episodes/196-nested-model-form-part-1
http://railscasts.com/episodes/197-nested-model-form-part-2
and one more thing, I added getRandomInt to jquery to create a unique identifier that is needed to avoid duplicate timestamps for fields instantly created without a time difference.
function add_fields(link, association, content) { // I changed below line by adding getRandomInt method to assure unique id. var new_id = new Date().getTime() + getRandomInt(1, 5000); var regexp = new RegExp("new_" + association, "g") $(".all_fields").append(content.replace(regexp, new_id)); } function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }
source share