Im using a link_to_function / insert_html to insert a partial into the page. Everything works fine, until i add another link_to_function / insert_html into the partial that is being rendered into the page. All of a sudden the outer link_to_function link stops working and throws this error:
"missing } after property list" [Break on this error] t.insert("content_items_1", { bottom: " ...[][position]\" type=\"hidden\" value="
I think the fact that the block of html/js is being double rendered into the quoted link is causing problems. This seems to be a bug with rails, but this also seems like a pretty common thing. Am i missing anything? Any easy work around?
Code: Main Page
<ol id="chapters">
<%= render :partial => 'chapter', :collection => @course.chapters %>
</ol>
<%= link_to_function("Add Chapter") do |page|
page.insert_html :bottom, :chapters, :partial => 'chapter', :object => Chapter.new
end %>
Code: Partial 'chapter'
<ol id="content_items_<%= @content_item_iter.to_s %>">
</ol>
<%= link_to_function "Add Content Item" do |page2|
page2.insert_html :bottom, "content_items_#{@content_item_iter.to_s}", :partial => 'content_item', :object => ContentItem.new
end %>
Here is the link that doesn't work (the Add Chapter link) - with \n,\n,\\n replaced with new line:
<a href="#" onclick="try {
Element.insert("chapters", { bottom: "
<li>
<input id=\"course_chapter_attributes_1_position\" name=\"course[chapter_attributes][1][position]\" type=\"hidden\" value=\"0\" />
<h2>
<label for=\"course_chapter_attributes_1_name\">Chapter:</label>
<input id=\"course_chapter_attributes_1_name\" name=\"course[chapter_attributes][1][name]\" size=\"30\" type=\"text\" />
</h2>
<ol id=\"content_items_1\">
</ol>
<a href=\"#\" onclick=\"try {
Element.insert("content_items_1", { bottom: "
<li>
<input id=\\"course_chapter_attributes__content_item_attributes__position\\" name=\\"course[chapter_attributes][][content_item_attributes][][position]\\" type=\\"hidden\\" value=\\"1\\" />
<h3>
<label for=\\"course_chapter_attributes__content_item_attributes__description\\">Article:</label>
<input id=\\"course_chapter_attributes__content_item_attributes__description\\" name=\\"course[chapter_attributes][][content_item_attributes][][description]\\" size=\\"30\\" type=\\"text\\" /> <br />
</h3>
<label for=\\"course_chapter_attributes__content_item_attributes__url\\">Link URL:</label>
<input id=\\"course_chapter_attributes__content_item_attributes__url\\" name=\\"course[chapter_attributes][][content_item_attributes][][url]\\" size=\\"30\\" type=\\"text\\" /> <br />
<label for=\\"course_chapter_attributes__content_item_attributes__youtube_id\\">Youtube Video ID:</label>
<input id=\\"course_chapter_attributes__content_item_attributes__youtube_id\\" name=\\"course[chapter_attributes][][content_item_attributes][][youtube_id]\\" size=\\"30\\" type=\\"text\\" /> <br />
<label for=\\"course_chapter_attributes__content_item_attributes__start_time\\">Start / Stop Time:</label>
<input id=\\"course_chapter_attributes__content_item_attributes__start_time\\" name=\\"course[chapter_attributes][][content_item_attributes][][start_time]\\" size=\\"30\\" type=\\"text\\" /> <input id=\\"course_chapter_attributes__content_item_attributes__end_time\\" name=\\"course[chapter_attributes][][content_item_attributes][][end_time]\\" size=\\"30\\" type=\\"text\\" />
</li>
" });
} catch (e) { alert('RJS error: ' + e.toString()); alert('Element.insert(\\"content_items_1\\", { bottom: \\"
<li>
<input id=\\\\\\"course_chapter_attributes__content_item_attributes__position\\\\\\" name=\\\\\\"course[chapter_attributes][][content_item_attributes][][position]\\\\\\" type=\\\\\\"hidden\\\\\\" value=\\\\\\"1\\\\\\" />
<h3>
<label for=\\\\\\"course_chapter_attributes__content_item_attributes__description\\\\\\">Article:</label>
<input id=\\\\\\"course_chapter_attributes__content_item_attributes__description\\\\\\" name=\\\\\\"course[chapter_attributes][][content_item_attributes][][description]\\\\\\" size=\\\\\\"30\\\\\\" type=\\\\\\"text\\\\\\" /> <br />
</h3>
<label for=\\\\\\"course_chapter_attributes__content_item_attributes__url\\\\\\">Link URL:</label>
<input id=\\\\\\"course_chapter_attributes__content_item_attributes__url\\\\\\" name=\\\\\\"course[chapter_attributes][][content_item_attributes][][url]\\\\\\" size=\\\\\\"30\\\\\\" type=\\\\\\"text\\\\\\" /> <br />
<label for=\\\\\\"course_chapter_attributes__content_item_attributes__youtube_id\\\\\\">Youtube Video ID:</label>
<input id=\\\\\\"course_chapter_attributes__content_item_attributes__youtube_id\\\\\\" name=\\\\\\"course[chapter_attributes][][content_item_attributes][][youtube_id]\\\\\\" size=\\\\\\"30\\\\\\" type=\\\\\\"text\\\\\\" /> <br />
<label for=\\\\\\"course_chapter_attributes__content_item_attributes__start_time\\\\\\">Start / Stop Time:</label>
<input id=\\\\\\"course_chapter_attributes__content_item_attributes__start_time\\\\\\" name=\\\\\\"course[chapter_attributes][][content_item_attributes][][start_time]\\\\\\" size=\\\\\\"30\\\\\\" type=\\\\\\"text\\\\\\" /> <input id=\\\\\\"course_chapter_attributes__content_item_attributes__end_time\\\\\\" name=\\\\\\"course[chapter_attributes][][content_item_attributes][][end_time]\\\\\\" size=\\\\\\"30\\\\\\" type=\\\\\\"text\\\\\\" />
</li>
\\" });'); throw e }; return false;\">Add Content Item</a>
</li>
" });
} catch (e) { alert('RJS error:
' + e.toString()); alert('Element.insert(\"chapters\", { bottom: \"
<li>
<input id=\\\"course_chapter_attributes_1_position\\\" name=\\\"course[chapter_attributes][1][position]\\\" type=\\\"hidden\\\" value=\\\"0\\\" />
<h2>
<label for=\\\"course_chapter_attributes_1_name\\\">Chapter:</label>
<input id=\\\"course_chapter_attributes_1_name\\\" name=\\\"course[chapter_attributes][1][name]\\\" size=\\\"30\\\" type=\\\"text\\\" />
</h2>
<ol id=\\\"content_items_1\\\">
</ol>
<a href=\\\"#\\\" onclick=\\\"try {
Element.insert("content_items_1", { bottom: "
<li>
<input id=\\\\"course_chapter_attributes__content_item_attributes__position\\\\" name=\\\\"course[chapter_attributes][][content_item_attributes][][position]\\\\" type=\\\\"hidden\\\\" value=\\\\"1\\\\" />
<h3>
<label for=\\\\"course_chapter_attributes__content_item_attributes__description\\\\">Article:</label>
<input id=\\\\"course_chapter_attributes__content_item_attributes__description\\\\" name=\\\\"course[chapter_attributes][][content_item_attributes][][description]\\\\" size=\\\\"30\\\\" type=\\\\"text\\\\" /> <br />
</h3>
<label for=\\\\"course_chapter_attributes__content_item_attributes__url\\\\">Link URL:</label>
<input id=\\\\"course_chapter_attributes__content_item_attributes__url\\\\" name=\\\\"course[chapter_attributes][][content_item_attributes][][url]\\\\" size=\\\\"30\\\\" type=\\\\"text\\\\" /> <br />
<label for=\\\\"course_chapter_attributes__content_item_attributes__youtube_id\\\\">Youtube Video ID:</label>
<input id=\\\\"course_chapter_attributes__content_item_attributes__youtube_id\\\\" name=\\\\"course[chapter_attributes][][content_item_attributes][][youtube_id]\\\\" size=\\\\"30\\\\" type=\\\\"text\\\\" /> <br />
<label for=\\\\"course_chapter_attributes__content_item_attributes__start_time\\\\">Start / Stop Time:</label>
<input id=\\\\"course_chapter_attributes__content_item_attributes__start_time\\\\" name=\\\\"course[chapter_attributes][][content_item_attributes][][start_time]\\\\" size=\\\\"30\\\\" type=\\\\"text\\\\" /> <input id=\\\\"course_chapter_attributes__content_item_attributes__end_time\\\\" name=\\\\"course[chapter_attributes][][content_item_attributes][][end_time]\\\\" size=\\\\"30\\\\" type=\\\\"text\\\\" />
</li>
" });
} catch (e) { alert(\'RJS error:
\' + e.toString()); alert(\'Element.insert(\\\\"content_items_1\\\\", { bottom: \\\\"
<li>
<input id=\\\\\\\\\\\\"course_chapter_attributes__content_item_attributes__position\\\\\\\\\\\\" name=\\\\\\\\\\\\"course[chapter_attributes][][content_item_attributes][][position]\\\\\\\\\\\\" type=\\\\\\\\\\\\"hidden\\\\\\\\\\\\" value=\\\\\\\\\\\\"1\\\\\\\\\\\\" />
<h3>
<label for=\\\\\\\\\\\\"course_chapter_attributes__content_item_attributes__description\\\\\\\\\\\\">Article:</label>
<input id=\\\\\\\\\\\\"course_chapter_attributes__content_item_attributes__description\\\\\\\\\\\\" name=\\\\\\\\\\\\"course[chapter_attributes][][content_item_attributes][][description]\\\\\\\\\\\\" size=\\\\\\\\\\\\"30\\\\\\\\\\\\" type=\\\\\\\\\\\\"text\\\\\\\\\\\\" /> <br />
</h3>
<label for=\\\\\\\\\\\\"course_chapter_attributes__content_item_attributes__url\\\\\\\\\\\\">Link URL:</label>
<input id=\\\\\\\\\\\\"course_chapter_attributes__content_item_attributes__url\\\\\\\\\\\\" name=\\\\\\\\\\\\"course[chapter_attributes][][content_item_attributes][][url]\\\\\\\\\\\\" size=\\\\\\\\\\\\"30\\\\\\\\\\\\" type=\\\\\\\\\\\\"text\\\\\\\\\\\\" /> <br />
<label for=\\\\\\\\\\\\"course_chapter_attributes__content_item_attributes__youtube_id\\\\\\\\\\\\">Youtube Video ID:</label>
<input id=\\\\\\\\\\\\"course_chapter_attributes__content_item_attributes__youtube_id\\\\\\\\\\\\" name=\\\\\\\\\\\\"course[chapter_attributes][][content_item_attributes][][youtube_id]\\\\\\\\\\\\" size=\\\\\\\\\\\\"30\\\\\\\\\\\\" type=\\\\\\\\\\\\"text\\\\\\\\\\\\" /> <br />
<label for=\\\\\\\\\\\\"course_chapter_attributes__content_item_attributes__start_time\\\\\\\\\\\\">Start / Stop Time:</label>
<input id=\\\\\\\\\\\\"course_chapter_attributes__content_item_attributes__start_time\\\\\\\\\\\\" name=\\\\\\\\\\\\"course[chapter_attributes][][content_item_attributes][][start_time]\\\\\\\\\\\\" size=\\\\\\\\\\\\"30\\\\\\\\\\\\" type=\\\\\\\\\\\\"text\\\\\\\\\\\\" /> <input id=\\\\\\\\\\\\"course_chapter_attributes__content_item_attributes__end_time\\\\\\\\\\\\" name=\\\\\\\\\\\\"course[chapter_attributes][][content_item_attributes][][end_time]\\\\\\\\\\\\" size=\\\\\\\\\\\\"30\\\\\\\\\\\\" type=\\\\\\\\\\\\"text\\\\\\\\\\\\" />
</li>
\\\\" });\'); throw e }; return false;\\\">Add Content Item</a>
</li>
\" });'); throw e }; return false;">Add Chapter</a>