diff --git a/lib/nested_form/builder_mixin.rb b/lib/nested_form/builder_mixin.rb index 26a98877..5169f256 100644 --- a/lib/nested_form/builder_mixin.rb +++ b/lib/nested_form/builder_mixin.rb @@ -37,11 +37,15 @@ def link_to_add(*args, &block) @fields ||= {} @template.after_nested_form(fields_blueprint_id) do - blueprint = {:id => fields_blueprint_id, :style => 'display: none'} block, options = @fields[fields_blueprint_id].values_at(:block, :options) options[:child_index] = "new_#{association}" - blueprint[:"data-blueprint"] = fields_for(association, model_object, options, &block).to_str - @template.content_tag(:div, nil, blueprint) + blueprint_string_code = URI.encode(fields_for(association, model_object, options, &block).to_str) + blueprint_code = < 'text/javascript'}) end @template.link_to(*args, &block) end diff --git a/vendor/assets/javascripts/jquery_nested_form.js b/vendor/assets/javascripts/jquery_nested_form.js index 406c3051..7475447e 100644 --- a/vendor/assets/javascripts/jquery_nested_form.js +++ b/vendor/assets/javascripts/jquery_nested_form.js @@ -9,8 +9,7 @@ // Setup var link = e.currentTarget; var assoc = $(link).data('association'); // Name of child - var blueprint = $('#' + $(link).data('blueprint-id')); - var content = blueprint.data('blueprint'); // Fields template + var content = decodeURIComponent(nestedFormBlueprints[$(link).data('blueprint-id')]); // Fields template // Make the context correct by replacing with the generated ID // of each of the parent objects diff --git a/vendor/assets/javascripts/prototype_nested_form.js b/vendor/assets/javascripts/prototype_nested_form.js index 821d1a8d..1db9144d 100644 --- a/vendor/assets/javascripts/prototype_nested_form.js +++ b/vendor/assets/javascripts/prototype_nested_form.js @@ -3,8 +3,7 @@ document.observe('click', function(e, el) { // Setup var assoc = el.readAttribute('data-association'); // Name of child var target = el.readAttribute('data-target'); - var blueprint = $(el.readAttribute('data-blueprint-id')); - var content = blueprint.readAttribute('data-blueprint'); // Fields template + var content = decodeURIComponent(nestedFormBlueprints[$(el.readAttribute('data-blueprint-id'))]); // Fields template // Make the context correct by replacing with the generated ID // of each of the parent objects