remove_fields & add field link not working on nested form in rails 3.0.9

前端 未结 2 1000
夕颜
夕颜 2021-01-21 06:04

I am following Ryan bates neted_forms episode 1 & 2 from rails casts, I have already implemented the nested-forms functionality in one of my project before & it\'s worki

2条回答
  •  爱一瞬间的悲伤
    2021-01-21 06:53

    Put this js in application.js file

    function remove_fields(link) {
    $(link).prev("input[type=hidden]").val("1");
    $(link).closest(".fields").hide(); }

    function add_fields(link, association, content) { var new_id = new Date().getTime(); var regexp = new RegExp("new_" + association, "g"); $(link).parent().before(content.replace(regexp, new_id)); }

提交回复
热议问题