Display html from javascript rails

I have a rendering of a partial that needs to be output to a div that is not displaying correctly. I tried in my index.js.haml:

= "$('.modal-body').html('#{escape_javascript(raw render("details"))}');"
= "$('.modal-body').html('#{escape_javascript(raw render("details")).html_safe}');"
= "$('.modal-body').html('#{escape_javascript(raw render("details").html_safe)}');"
= "$('.modal-body').html('#{raw escape_javascript(raw render("details"))}');"
= "$('.modal-body').html('#{raw escape_javascript(raw render("details").html_safe)}');"
= "$('.modal-body').html('#{raw escape_javascript(raw render("details")).html_safe}');"

      

and they all output the following:

enter image description here

If I remove escape_javascript it doesn't work anymore.

+3


source to share


2 answers


Thanks to Emu who posted the answer on the ERB, I found a way to do it in haml:



:plain
  $('.modal-body').html('#{j render partial: 'details'}'); // in HAML

$('.modal-body').html('<%= j render partial: 'details'%>'); //in ERB

      

+1


source


$('.modal-body').html('<%=j render partial: 'details' %>'); // in HTML

$('.modal-body').html('#{j render partial: 'details'}');  // in HAML

      



0


source







All Articles