0

Here is a simple example of the problem.

http://gist.github.com/235729

In short, if you have a index.rhtml with:

<%= link_to_function "A link to insert a partial with nested insert_html" do |page|
      page.insert_html :top, :with_a_nested_insert_html, :partial => 'example_partial_with_nested_insert_html'
    end %>

And a _example_partial_with_nested_insert_html.rhtml

<%= link_to_function "A nested link to insert_html" do |page|
      page.insert_html :top, :with_a_nested_insert_html, :partial => 'you_wont_see_this'
    end %>

It breaks the "A link to insert a partial with nested insert_html". I am thinking something needs to be done to protect the javascript in the partial.

Any thoughts?

Ryan McGeary
  • 235,892
  • 13
  • 95
  • 104
AGreyCrane
  • 37
  • 4

3 Answers3

1

Here's how I do it.

<%= link_to_function( "insert it", :id => 'foo') do |page| 
            partial = escape_javascript(render :partial => "my_partial", :object => Object.new)
            page <<  "$('#my_div').append(\"#{partial}\")"
        end %>
inkdeep
  • 1,127
  • 9
  • 18
0

I didn't try but I strongly think the syntax should be more something like :

<% link_to_function "A link to insert a partial with nested insert_html" do |page|
   <%= page.insert_html :top, :with_a_nested_insert_html, :partial => 'example_partial_with_nested_insert_html' %>
<% end %>
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Mike
  • 5,165
  • 6
  • 35
  • 50
0

Try using escape_javascript before rendering the partials - see this other question.

Community
  • 1
  • 1
kikito
  • 51,734
  • 32
  • 149
  • 189