views:

217

answers:

0

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(&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>