Permalink
Browse files

don't prepend new_ to the nested fields keys

In order to be compatible with strong_parameters as it detects nested
fields array only with numeric keys.

Closes #199.
  • Loading branch information...
1 parent 4407101 commit ec5ed6654ccd78d4cefab5a03ac66e3493855aa7 @lest lest committed Oct 5, 2012
View
@@ -45,6 +45,6 @@ def check_form
click_link 'Add new task'
click_link 'Add new milestone'
name = find('.fields .fields input[id$=name]')[:name]
- name.should match(/\Aproject\[tasks_attributes\]\[new_\d+\]\[milestones_attributes\]\[new_\d+\]\[name\]\z/)
+ name.should match(/\Aproject\[tasks_attributes\]\[\d+\]\[milestones_attributes\]\[\d+\]\[name\]\z/)
end
end
@@ -12,17 +12,17 @@ jQuery(function($) {
var blueprint = $('#' + $(link).data('blueprint-id'));
var content = blueprint.data('blueprint'); // Fields template
- // Make the context correct by replacing new_<parents> with the generated ID
+ // Make the context correct by replacing <parents> with the generated ID
// of each of the parent objects
var context = ($(link).closest('.fields').closestChild('input, textarea').eq(0).attr('name') || '').replace(new RegExp('\[[a-z]+\]$'), '');
// context will be something like this for a brand new form:
- // project[tasks_attributes][new_1255929127459][assignments_attributes][new_1255929128105]
+ // project[tasks_attributes][1255929127459][assignments_attributes][1255929128105]
// or for an edit form:
// project[tasks_attributes][0][assignments_attributes][1]
if (context) {
var parentNames = context.match(/[a-z_]+_attributes/g) || [];
- var parentIds = context.match(/(new_)?[0-9]+/g) || [];
+ var parentIds = context.match(/[0-9]+/g) || [];
for(var i = 0; i < parentNames.length; i++) {
if(parentIds[i]) {
@@ -40,7 +40,7 @@ jQuery(function($) {
// Make a unique ID for the new child
var regexp = new RegExp('new_' + assoc, 'g');
var new_id = new Date().getTime();
- content = content.replace(regexp, "new_" + new_id);
+ content = content.replace(regexp, new_id);
var field = this.insertFields(content, assoc, link);
// bubble up event upto document (through form)
@@ -5,17 +5,17 @@ document.observe('click', function(e, el) {
var blueprint = $(el.readAttribute('data-blueprint-id'));
var content = blueprint.readAttribute('data-blueprint'); // Fields template
- // Make the context correct by replacing new_<parents> with the generated ID
+ // Make the context correct by replacing <parents> with the generated ID
// of each of the parent objects
var context = (el.getOffsetParent('.fields').firstDescendant().readAttribute('name') || '').replace(new RegExp('\[[a-z]+\]$'), '');
// context will be something like this for a brand new form:
- // project[tasks_attributes][new_1255929127459][assignments_attributes][new_1255929128105]
+ // project[tasks_attributes][1255929127459][assignments_attributes][1255929128105]
// or for an edit form:
// project[tasks_attributes][0][assignments_attributes][1]
if(context) {
var parent_names = context.match(/[a-z_]+_attributes/g) || [];
- var parent_ids = context.match(/(new_)?[0-9]+/g) || [];
+ var parent_ids = context.match(/[0-9]+/g) || [];
for(i = 0; i < parent_names.length; i++) {
if(parent_ids[i]) {
@@ -33,7 +33,7 @@ document.observe('click', function(e, el) {
// Make a unique ID for the new child
var regexp = new RegExp('new_' + assoc, 'g');
var new_id = new Date().getTime();
- content = content.replace(regexp, "new_" + new_id);
+ content = content.replace(regexp, new_id);
var field = el.insert({ before: content });
field.fire('nested:fieldAdded', {field: field});

0 comments on commit ec5ed66

Please sign in to comment.