Question

Voici un exemple simple du problème.

http://gist.github.com/235729

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 un _Example_Partial_With_Nted_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 un partiel avec INSERT_HTML". Je pense que quelque chose doit être fait pour protéger le javascript dans le partiel.

Des pensées?

Était-ce utile?

La solution

Voici comment je 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 %>

Autres conseils

Essayez d'utiliser Escape_javascript avant de rendre les partiels - Voir cette autre question.

Je n'ai pas essayé mais je pense fortement que 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 %>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top