Rendering partial from js.erb template creates html tag remnant content

I have a problem rendering @resultsfrom show.js.erb. The result is as follows:output from show.js.erb template

show.js.erb

$('#results').empty();
$('#results').html("<ul><%= escape_javascript(render(@results)).html_safe %></ul>");

_result.html.erb

<li>
  <%= link_to(result.title, result.uri) %><br>
  <span class="urls"><%= result.uri %></span>
</li>

Using _result.html.erbin show.html.erb:

<ul>
  <%= render @results %>
</ul>

produces the correct conclusion.

The alleged offender <%= escape_javascript(render(@results)).html_safe %>. I tried <%= raw(escape_javascript(render@results)) %>but no luck. Application created with Rails 3.0.8.

Edit 1:

Longer version of show.js.erb :

$('#results').empty();
$('#results').html("<ul><%= escape_javascript(render(:partial => "results/result",   :collection => @results)).html_safe %></ul>");

remains the same as in the image with a>, li>and something else.

Edit 2:

HTML displayed show.js.erb: enter image description here

Edit 3:

<a href="http://jasonseifer.com/2010/04/06/rake-tutorial">Rake Tutorial | Jason Seifera&gt;<br>  <span class="urls">http://jasonseifer.com/2010/04/06/rake-tutorialspan&gt;li&gt;</span></a>

Change 4:

without html_safe:

$('#results').empty();
$('#results').html('<ul><%= escape_javascript render(@results) %></ul>');

Conclusion:

output without html_safe

</already have it escape_javascript.

Edit 5: It works! At last!

$('#results').html('<%= escape_javascript("<ul>#{render(@results)}</ul>").html_safe %>');

Dogbert .html('') .html_safe.

+3
3

js.erb

$('#results').html(<%= escape_javascript "<ul>#{render(@results)}</ul>"%>);
+7

:

  • ; empty()

    $('#results').empty();
    
  • , .

    $('#results').html("<ul><%= escape_javascript(render( :partial => "results/result", :collection => @results)).html_safe %></ul>");
    

.html('')

+3
+1
source

All Articles