From 03994be49a6d7ae3055878f4edeca474e933e61e Mon Sep 17 00:00:00 2001 From: Ramon Snir Date: Sun, 17 Aug 2014 09:07:34 +0300 Subject: [PATCH 1/4] Moved blueprint from DOM to memory --- README.md | 2 -- lib/nested_form/builder_mixin.rb | 12 ++++++++---- vendor/assets/javascripts/jquery_nested_form.js | 3 +-- vendor/assets/javascripts/prototype_nested_form.js | 3 +-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 667b9dec..69e853a1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # Nested Form -[Build Status](http://travis-ci.org/ryanb/nested_form) - This is a Rails gem for conveniently manage multiple nested models in a single form. It does so in an unobtrusive way through jQuery or Prototype. This gem only works with Rails 3. See the [rails2 branch](https://github.com/ryanb/nested_form/tree/rails2) for a plugin to work in Rails 2. diff --git a/lib/nested_form/builder_mixin.rb b/lib/nested_form/builder_mixin.rb index 26a98877..86c27ff1 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 @@ -62,7 +66,7 @@ def link_to_remove(*args, &block) options[:class] = [options[:class], "remove_nested_fields"].compact.join(" ") # Extracting "milestones" from "...[milestones_attributes][...]" - md = object_name.to_s.match /(\w+)_attributes\](?:\[[\w\d]+\])?$/ + md = object_name.to_s.match /(\w+)_attributes\]\[[\w\d]+\]$/ association = md && md[1] options["data-association"] = association 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..fbf31d3a 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 From 4f59a01e5b3e012aee4765f701f69ed7ad2ee434 Mon Sep 17 00:00:00 2001 From: Ramon Snir Date: Sun, 17 Aug 2014 09:11:14 +0300 Subject: [PATCH 2/4] match ryanb/master --- lib/nested_form/builder_mixin.rb | 2 +- vendor/assets/javascripts/prototype_nested_form.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/nested_form/builder_mixin.rb b/lib/nested_form/builder_mixin.rb index 86c27ff1..81fe5b13 100644 --- a/lib/nested_form/builder_mixin.rb +++ b/lib/nested_form/builder_mixin.rb @@ -66,7 +66,7 @@ def link_to_remove(*args, &block) options[:class] = [options[:class], "remove_nested_fields"].compact.join(" ") # Extracting "milestones" from "...[milestones_attributes][...]" - md = object_name.to_s.match /(\w+)_attributes\]\[[\w\d]+\]$/ + md = object_name.to_s.match /(\w+)_attributes\](?:\[[\w\d]+\])?$/ association = md && md[1] options["data-association"] = association diff --git a/vendor/assets/javascripts/prototype_nested_form.js b/vendor/assets/javascripts/prototype_nested_form.js index fbf31d3a..1db9144d 100644 --- a/vendor/assets/javascripts/prototype_nested_form.js +++ b/vendor/assets/javascripts/prototype_nested_form.js @@ -3,7 +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 content = decodeURIComponent(nestedFormBlueprints[$(el.readAttribute('data-blueprint-id'))]); // 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 From 19aa080540f2bee113153c70354e7d4ace457bb7 Mon Sep 17 00:00:00 2001 From: Ramon Snir Date: Sun, 17 Aug 2014 09:13:34 +0300 Subject: [PATCH 3/4] to be on the safe side --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 69e853a1..667b9dec 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Nested Form +[Build Status](http://travis-ci.org/ryanb/nested_form) + This is a Rails gem for conveniently manage multiple nested models in a single form. It does so in an unobtrusive way through jQuery or Prototype. This gem only works with Rails 3. See the [rails2 branch](https://github.com/ryanb/nested_form/tree/rails2) for a plugin to work in Rails 2. From b376532ff0f34f44cbfb5dec8cb6a163b69e1435 Mon Sep 17 00:00:00 2001 From: Ramon Snir Date: Sun, 17 Aug 2014 10:34:32 +0300 Subject: [PATCH 4/4] Do not rename things right before committing. --- lib/nested_form/builder_mixin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nested_form/builder_mixin.rb b/lib/nested_form/builder_mixin.rb index 81fe5b13..5169f256 100644 --- a/lib/nested_form/builder_mixin.rb +++ b/lib/nested_form/builder_mixin.rb @@ -43,7 +43,7 @@ def link_to_add(*args, &block) blueprint_code = < 'text/javascript'}) end