0

这是一个简单的问题示例。

http://gist.github.com/235729

简而言之,如果你有一个 index.rhtml :

<%= 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 %>

还有一个 _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 %>

它打破了“使用嵌套的 insert_html 插入部分内容的链接”。我认为需要做一些事情来保护部分的javascript。

有什么想法吗?

4

3 回答 3

1

这是我的做法。

<%= 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 %>
于 2010-01-28T23:45:31.150 回答
0

我没有尝试,但我强烈认为语法应该更像:

<% 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 %>
于 2009-11-16T06:49:40.193 回答
0

在渲染部分之前尝试使用 escape_javascript -请参阅this other question

于 2009-11-16T10:08:27.493 回答