我使用link_to_function / insert_html将部分插入页面。一切正常,直到我将另一个link_to_function / insert_html添加到正在呈现到页面中的部分。外部link_to_function链接突然停止工作并抛出此错误:
在属性列表后“丢失”“[中断 关于这个错误] t.insert(“content_items_1”,{bottom: “... [] [position] \”type = \“hidden \” 值=“
我认为html / js块被双重渲染到引用链接的事实导致了问题。这似乎是rails的错误,但这似乎也很常见。我错过了什么吗?任何简单的解决方法?
代码:主页
<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 %>
代码:部分'章'
<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 %>
这是不起作用的链接(添加章节链接) - 将\ n,\ n,\\ n替换为新行:
<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>
答案 0 :(得分:0)
错误似乎表明您的样式表缺少结束}。