2009-11-16 41 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 %>