0
@@ -160,7 +160,7 @@ class AssociatedFormHelperTest < Test::Unit::TestCase
0
should "produce the following link" do
0
# this is a way of testing the whole link
0
- <a class=\"something\" href=\"#\" onclick=\"if (typeof attribute_fu_comment_count == 'undefined') attribute_fu_comment_count = 0;\nnew Insertion.Bottom('comments', new Template(null).evaluate({'number': --attribute_fu_comment_count})
); return false;\">Add Comment</a>
0
+ <a class=\"something\" href=\"#\" onclick=\"if (typeof attribute_fu_comment_count == 'undefined') attribute_fu_comment_count = 0;\nnew Insertion.Bottom('comments', new Template(null).evaluate({'number': --attribute_fu_comment_count})
.gsub(/__number_/, attribute_fu_comment_count)); return false;\">Add Comment</a>
0
@@ -198,7 +198,7 @@ class AssociatedFormHelperTest < Test::Unit::TestCase
0
should "produce the following link" do
0
# this is a way of testing the whole link
0
- <a href=\"#\" onclick=\"if (typeof attribute_fu_comment_count == 'undefined') attribute_fu_comment_count = 0;\nnew Insertion.Bottom('something_comments', new Template(null).evaluate({'number': --attribute_fu_comment_count})
); return false;\">Add Comment</a>
0
+ <a href=\"#\" onclick=\"if (typeof attribute_fu_comment_count == 'undefined') attribute_fu_comment_count = 0;\nnew Insertion.Bottom('something_comments', new Template(null).evaluate({'number': --attribute_fu_comment_count})
.gsub(/__number_/, attribute_fu_comment_count)); return false;\">Add Comment</a>
0
@@ -236,7 +236,7 @@ class AssociatedFormHelperTest < Test::Unit::TestCase
0
should "produce the following link" do
0
# this is a way of testing the whole link
0
- <a href=\"#\" onclick=\"if (typeof attribute_fu_comment_count == 'undefined') attribute_fu_comment_count = 0;\nnew Insertion.Bottom($(this).up(".something_comments"), new Template(null).evaluate({'number': --attribute_fu_comment_count})
); return false;\">Add Comment</a>
0
+ <a href=\"#\" onclick=\"if (typeof attribute_fu_comment_count == 'undefined') attribute_fu_comment_count = 0;\nnew Insertion.Bottom($(this).up(".something_comments"), new Template(null).evaluate({'number': --attribute_fu_comment_count})
.gsub(/__number_/, attribute_fu_comment_count)); return false;\">Add Comment</a>
Comments
cjkihlbom, can you explain exactly what is happening in this commit? I’m fairly sure this is doing what I’m trying to get from attribute_fu, which is to create unique identifiers for elements in partials brought in from the add_associated_link. I just can’t figure out how to get that unique id.
Sure, here’s the gist of it:
The problem:
fields_for sanitizes object names when generating IDs.
'project[todo_attributes][new][#{number}]'becomes'project_todo_attributes__new_____number_', causing the Template, which looks for the string'#{number}'to not replace the number in the ID with the variable count. That means that all associated fields generated by clicking the link will have the same IDs.The fix (hack):
gsub the
'__number_'with the variable count after the Template evaluation.Not the cleanest solution, but it works.