2009-10-19 70 views
3

Im使用link_to_function/insert_html将部分插入到页面中。一切正常,直到我将另一个link_to_function/insert_html添加到正在呈现到页面中的部分中。突然外link_to_function链接停止工作,并抛出这个错误:嵌套的link_to_function/insert_html导致javascript错误

"missing } after property list" [Break on this error] t.insert("content_items_1", { bottom: " ...[][position]\" type=\"hidden\" value="

我认为的事实,HTML/JS的块被双重渲染到引用链接导致的问题。这似乎是一个与轨道的错误,但这也似乎是一个很常见的事情。我错过了什么?任何简单的解决方法?

代码:主页

<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(&quot;chapters&quot;, { bottom: &quot; 
    &lt;li&gt; 
     &lt;input id=\&quot;course_chapter_attributes_1_position\&quot; name=\&quot;course[chapter_attributes][1][position]\&quot; type=\&quot;hidden\&quot; value=\&quot;0\&quot; /&gt; 
     &lt;h2&gt; 
     &lt;label for=\&quot;course_chapter_attributes_1_name\&quot;&gt;Chapter:&lt;/label&gt; 
     &lt;input id=\&quot;course_chapter_attributes_1_name\&quot; name=\&quot;course[chapter_attributes][1][name]\&quot; size=\&quot;30\&quot; type=\&quot;text\&quot; /&gt; 
     &lt;/h2&gt; 
     &lt;ol id=\&quot;content_items_1\&quot;&gt; 
     &lt;/ol&gt; 
     &lt;a href=\&quot;#\&quot; onclick=\&quot;try { 
Element.insert(&quot;content_items_1&quot;, { bottom: &quot;   
      &lt;li&gt; 
      &lt;input id=\\&quot;course_chapter_attributes__content_item_attributes__position\\&quot; name=\\&quot;course[chapter_attributes][][content_item_attributes][][position]\\&quot; type=\\&quot;hidden\\&quot; value=\\&quot;1\\&quot; /&gt; 
      &lt;h3&gt; 
      &lt;label for=\\&quot;course_chapter_attributes__content_item_attributes__description\\&quot;&gt;Article:&lt;/label&gt; 
      &lt;input id=\\&quot;course_chapter_attributes__content_item_attributes__description\\&quot; name=\\&quot;course[chapter_attributes][][content_item_attributes][][description]\\&quot; size=\\&quot;30\\&quot; type=\\&quot;text\\&quot; /&gt; &lt;br /&gt; 
      &lt;/h3&gt; 
      &lt;label for=\\&quot;course_chapter_attributes__content_item_attributes__url\\&quot;&gt;Link URL:&lt;/label&gt; 
      &lt;input id=\\&quot;course_chapter_attributes__content_item_attributes__url\\&quot; name=\\&quot;course[chapter_attributes][][content_item_attributes][][url]\\&quot; size=\\&quot;30\\&quot; type=\\&quot;text\\&quot; /&gt; &lt;br /&gt; 
      &lt;label for=\\&quot;course_chapter_attributes__content_item_attributes__youtube_id\\&quot;&gt;Youtube Video ID:&lt;/label&gt; 
      &lt;input id=\\&quot;course_chapter_attributes__content_item_attributes__youtube_id\\&quot; name=\\&quot;course[chapter_attributes][][content_item_attributes][][youtube_id]\\&quot; size=\\&quot;30\\&quot; type=\\&quot;text\\&quot; /&gt; &lt;br /&gt; 
      &lt;label for=\\&quot;course_chapter_attributes__content_item_attributes__start_time\\&quot;&gt;Start/Stop Time:&lt;/label&gt; 
      &lt;input id=\\&quot;course_chapter_attributes__content_item_attributes__start_time\\&quot; name=\\&quot;course[chapter_attributes][][content_item_attributes][][start_time]\\&quot; size=\\&quot;30\\&quot; type=\\&quot;text\\&quot; /&gt; &lt;input id=\\&quot;course_chapter_attributes__content_item_attributes__end_time\\&quot; name=\\&quot;course[chapter_attributes][][content_item_attributes][][end_time]\\&quot; size=\\&quot;30\\&quot; type=\\&quot;text\\&quot; /&gt; 
      &lt;/li&gt; 


&quot; }); 
} catch (e) { alert('RJS error: ' + e.toString()); alert('Element.insert(\\&quot;content_items_1\\&quot;, { bottom: \\&quot;   
      &lt;li&gt; 
      &lt;input id=\\\\\\&quot;course_chapter_attributes__content_item_attributes__position\\\\\\&quot; name=\\\\\\&quot;course[chapter_attributes][][content_item_attributes][][position]\\\\\\&quot; type=\\\\\\&quot;hidden\\\\\\&quot; value=\\\\\\&quot;1\\\\\\&quot; /&gt; 
      &lt;h3&gt; 
      &lt;label for=\\\\\\&quot;course_chapter_attributes__content_item_attributes__description\\\\\\&quot;&gt;Article:&lt;/label&gt; 
      &lt;input id=\\\\\\&quot;course_chapter_attributes__content_item_attributes__description\\\\\\&quot; name=\\\\\\&quot;course[chapter_attributes][][content_item_attributes][][description]\\\\\\&quot; size=\\\\\\&quot;30\\\\\\&quot; type=\\\\\\&quot;text\\\\\\&quot; /&gt; &lt;br /&gt; 
      &lt;/h3&gt; 
      &lt;label for=\\\\\\&quot;course_chapter_attributes__content_item_attributes__url\\\\\\&quot;&gt;Link URL:&lt;/label&gt; 
      &lt;input id=\\\\\\&quot;course_chapter_attributes__content_item_attributes__url\\\\\\&quot; name=\\\\\\&quot;course[chapter_attributes][][content_item_attributes][][url]\\\\\\&quot; size=\\\\\\&quot;30\\\\\\&quot; type=\\\\\\&quot;text\\\\\\&quot; /&gt; &lt;br /&gt; 
      &lt;label for=\\\\\\&quot;course_chapter_attributes__content_item_attributes__youtube_id\\\\\\&quot;&gt;Youtube Video ID:&lt;/label&gt; 
      &lt;input id=\\\\\\&quot;course_chapter_attributes__content_item_attributes__youtube_id\\\\\\&quot; name=\\\\\\&quot;course[chapter_attributes][][content_item_attributes][][youtube_id]\\\\\\&quot; size=\\\\\\&quot;30\\\\\\&quot; type=\\\\\\&quot;text\\\\\\&quot; /&gt; &lt;br /&gt; 
      &lt;label for=\\\\\\&quot;course_chapter_attributes__content_item_attributes__start_time\\\\\\&quot;&gt;Start/Stop Time:&lt;/label&gt; 
      &lt;input id=\\\\\\&quot;course_chapter_attributes__content_item_attributes__start_time\\\\\\&quot; name=\\\\\\&quot;course[chapter_attributes][][content_item_attributes][][start_time]\\\\\\&quot; size=\\\\\\&quot;30\\\\\\&quot; type=\\\\\\&quot;text\\\\\\&quot; /&gt; &lt;input id=\\\\\\&quot;course_chapter_attributes__content_item_attributes__end_time\\\\\\&quot; name=\\\\\\&quot;course[chapter_attributes][][content_item_attributes][][end_time]\\\\\\&quot; size=\\\\\\&quot;30\\\\\\&quot; type=\\\\\\&quot;text\\\\\\&quot; /&gt; 
      &lt;/li&gt; 



\\&quot; });'); throw e }; return false;\&quot;&gt;Add Content Item&lt;/a&gt; 
    &lt;/li&gt; 


&quot; }); 
    } catch (e) { alert('RJS error: 

' + e.toString()); alert('Element.insert(\&quot;chapters\&quot;, { bottom: \&quot; 
    &lt;li&gt; 
     &lt;input id=\\\&quot;course_chapter_attributes_1_position\\\&quot; name=\\\&quot;course[chapter_attributes][1][position]\\\&quot; type=\\\&quot;hidden\\\&quot; value=\\\&quot;0\\\&quot; /&gt; 
     &lt;h2&gt; 
     &lt;label for=\\\&quot;course_chapter_attributes_1_name\\\&quot;&gt;Chapter:&lt;/label&gt; 
     &lt;input id=\\\&quot;course_chapter_attributes_1_name\\\&quot; name=\\\&quot;course[chapter_attributes][1][name]\\\&quot; size=\\\&quot;30\\\&quot; type=\\\&quot;text\\\&quot; /&gt; 
     &lt;/h2&gt; 
     &lt;ol id=\\\&quot;content_items_1\\\&quot;&gt; 
     &lt;/ol&gt; 
     &lt;a href=\\\&quot;#\\\&quot; onclick=\\\&quot;try { 
Element.insert(&quot;content_items_1&quot;, { bottom: &quot;   
      &lt;li&gt; 
      &lt;input id=\\\\&quot;course_chapter_attributes__content_item_attributes__position\\\\&quot; name=\\\\&quot;course[chapter_attributes][][content_item_attributes][][position]\\\\&quot; type=\\\\&quot;hidden\\\\&quot; value=\\\\&quot;1\\\\&quot; /&gt; 
      &lt;h3&gt; 
      &lt;label for=\\\\&quot;course_chapter_attributes__content_item_attributes__description\\\\&quot;&gt;Article:&lt;/label&gt; 
      &lt;input id=\\\\&quot;course_chapter_attributes__content_item_attributes__description\\\\&quot; name=\\\\&quot;course[chapter_attributes][][content_item_attributes][][description]\\\\&quot; size=\\\\&quot;30\\\\&quot; type=\\\\&quot;text\\\\&quot; /&gt; &lt;br /&gt; 
      &lt;/h3&gt; 
      &lt;label for=\\\\&quot;course_chapter_attributes__content_item_attributes__url\\\\&quot;&gt;Link URL:&lt;/label&gt; 
      &lt;input id=\\\\&quot;course_chapter_attributes__content_item_attributes__url\\\\&quot; name=\\\\&quot;course[chapter_attributes][][content_item_attributes][][url]\\\\&quot; size=\\\\&quot;30\\\\&quot; type=\\\\&quot;text\\\\&quot; /&gt; &lt;br /&gt; 
      &lt;label for=\\\\&quot;course_chapter_attributes__content_item_attributes__youtube_id\\\\&quot;&gt;Youtube Video ID:&lt;/label&gt; 
      &lt;input id=\\\\&quot;course_chapter_attributes__content_item_attributes__youtube_id\\\\&quot; name=\\\\&quot;course[chapter_attributes][][content_item_attributes][][youtube_id]\\\\&quot; size=\\\\&quot;30\\\\&quot; type=\\\\&quot;text\\\\&quot; /&gt; &lt;br /&gt; 
      &lt;label for=\\\\&quot;course_chapter_attributes__content_item_attributes__start_time\\\\&quot;&gt;Start/Stop Time:&lt;/label&gt; 
      &lt;input id=\\\\&quot;course_chapter_attributes__content_item_attributes__start_time\\\\&quot; name=\\\\&quot;course[chapter_attributes][][content_item_attributes][][start_time]\\\\&quot; size=\\\\&quot;30\\\\&quot; type=\\\\&quot;text\\\\&quot; /&gt; &lt;input id=\\\\&quot;course_chapter_attributes__content_item_attributes__end_time\\\\&quot; name=\\\\&quot;course[chapter_attributes][][content_item_attributes][][end_time]\\\\&quot; size=\\\\&quot;30\\\\&quot; type=\\\\&quot;text\\\\&quot; /&gt; 
      &lt;/li&gt; 



&quot; }); 
} catch (e) { alert(\'RJS error: 

\' + e.toString()); alert(\'Element.insert(\\\\&quot;content_items_1\\\\&quot;, { bottom: \\\\&quot;   
      &lt;li&gt; 
      &lt;input id=\\\\\\\\\\\\&quot;course_chapter_attributes__content_item_attributes__position\\\\\\\\\\\\&quot; name=\\\\\\\\\\\\&quot;course[chapter_attributes][][content_item_attributes][][position]\\\\\\\\\\\\&quot; type=\\\\\\\\\\\\&quot;hidden\\\\\\\\\\\\&quot; value=\\\\\\\\\\\\&quot;1\\\\\\\\\\\\&quot; /&gt; 
      &lt;h3&gt; 
      &lt;label for=\\\\\\\\\\\\&quot;course_chapter_attributes__content_item_attributes__description\\\\\\\\\\\\&quot;&gt;Article:&lt;/label&gt; 
      &lt;input id=\\\\\\\\\\\\&quot;course_chapter_attributes__content_item_attributes__description\\\\\\\\\\\\&quot; name=\\\\\\\\\\\\&quot;course[chapter_attributes][][content_item_attributes][][description]\\\\\\\\\\\\&quot; size=\\\\\\\\\\\\&quot;30\\\\\\\\\\\\&quot; type=\\\\\\\\\\\\&quot;text\\\\\\\\\\\\&quot; /&gt; &lt;br /&gt; 
      &lt;/h3&gt; 
      &lt;label for=\\\\\\\\\\\\&quot;course_chapter_attributes__content_item_attributes__url\\\\\\\\\\\\&quot;&gt;Link URL:&lt;/label&gt; 
      &lt;input id=\\\\\\\\\\\\&quot;course_chapter_attributes__content_item_attributes__url\\\\\\\\\\\\&quot; name=\\\\\\\\\\\\&quot;course[chapter_attributes][][content_item_attributes][][url]\\\\\\\\\\\\&quot; size=\\\\\\\\\\\\&quot;30\\\\\\\\\\\\&quot; type=\\\\\\\\\\\\&quot;text\\\\\\\\\\\\&quot; /&gt; &lt;br /&gt; 
      &lt;label for=\\\\\\\\\\\\&quot;course_chapter_attributes__content_item_attributes__youtube_id\\\\\\\\\\\\&quot;&gt;Youtube Video ID:&lt;/label&gt; 
      &lt;input id=\\\\\\\\\\\\&quot;course_chapter_attributes__content_item_attributes__youtube_id\\\\\\\\\\\\&quot; name=\\\\\\\\\\\\&quot;course[chapter_attributes][][content_item_attributes][][youtube_id]\\\\\\\\\\\\&quot; size=\\\\\\\\\\\\&quot;30\\\\\\\\\\\\&quot; type=\\\\\\\\\\\\&quot;text\\\\\\\\\\\\&quot; /&gt; &lt;br /&gt; 
      &lt;label for=\\\\\\\\\\\\&quot;course_chapter_attributes__content_item_attributes__start_time\\\\\\\\\\\\&quot;&gt;Start/Stop Time:&lt;/label&gt; 
      &lt;input id=\\\\\\\\\\\\&quot;course_chapter_attributes__content_item_attributes__start_time\\\\\\\\\\\\&quot; name=\\\\\\\\\\\\&quot;course[chapter_attributes][][content_item_attributes][][start_time]\\\\\\\\\\\\&quot; size=\\\\\\\\\\\\&quot;30\\\\\\\\\\\\&quot; type=\\\\\\\\\\\\&quot;text\\\\\\\\\\\\&quot; /&gt; &lt;input id=\\\\\\\\\\\\&quot;course_chapter_attributes__content_item_attributes__end_time\\\\\\\\\\\\&quot; name=\\\\\\\\\\\\&quot;course[chapter_attributes][][content_item_attributes][][end_time]\\\\\\\\\\\\&quot; size=\\\\\\\\\\\\&quot;30\\\\\\\\\\\\&quot; type=\\\\\\\\\\\\&quot;text\\\\\\\\\\\\&quot; /&gt; 
      &lt;/li&gt; 



\\\\&quot; });\'); throw e }; return false;\\\&quot;&gt;Add Content Item&lt;/a&gt; 
    &lt;/li&gt; 


\&quot; });'); throw e }; return false;">Add Chapter</a> 
+0

你能发布整个错误和生成的JavaScript吗? – EmFi 2009-10-19 04:14:46

+0

EmFi,我不能得到完整的错误(萤火虫不会给我任何更多信息),但我只是添加了生成的链接,并不起作用。 – LMH 2009-10-19 04:39:32

+0

对不起,错误看起来像一个片段。经仔细检查,这是一个完整的错误。 生成javascript真的很难阅读,你有可能用新的换行符替换\ n吗?我可以做到这一点,但这只能帮助我,而不是其他任何人看你的问题。 – EmFi 2009-10-19 06:17:30

回答

0

该错误似乎表示您的样式表缺少关闭}大括号。

相关问题