2009-11-16 4 views
0

Voici un exemple simple du problème.imbriqué link_to_function/insert_html ne fonctionne pas

http://gist.github.com/235729

En bref, si vous avez un index.rhtml avec:

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

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

Il brise le « Un lien pour insérer une partie avec insert_html imbriqué ". Je pense que quelque chose doit être fait pour protéger le javascript dans le partiel.

Des pensées?

Répondre

1

Voici comment je le fais.

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

Je n'ai pas essayé mais je pense fortement la syntaxe devrait être plus quelque chose comme:

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