2009-11-16 39 views
0

这是一个简单的问题示例。嵌套的link_to_function/insert_html不起作用

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。

有什么想法?

回答

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