0

I have a .js.erb file that renders a partial like so:

$("#tasks").append("<%= escape_javascript(render :partial => "task_from_app") %>");

I now need to put some javascript inside task_from_app, but the javascript doesn't work.

Removing escape_javascript doesn't work either - no error is shown and the partial isn't rendered on the page.

How can I get the partial to render if it includes javascript?

sscirrus
  • 55,407
  • 41
  • 135
  • 228

1 Answers1

0
$("#tasks").append("<%= escape_javascript(render :partial => "task_from_app").html_safe %>");
Salil
  • 46,566
  • 21
  • 122
  • 156
  • The javascript doesn't render with your version. – sscirrus Apr 29 '13 at 05:57
  • It works for me, have you tried `single quotes` like `.append('<%= %>')` – Salil Apr 29 '13 at 06:03
  • I'm afraid it's not working for me. I'm seeing the partial render just fine, but the javascript is missing. – sscirrus Apr 29 '13 at 06:07
  • Is there any way to append these partials and have the javascript run? I don't really want to escape the javascript if this means it wont actually execute. – sscirrus Apr 29 '13 at 06:12
  • Ref:- http://stackoverflow.com/questions/5933747/why-isnt-this-method-rendering-my-js-erb-file – Salil Apr 29 '13 at 06:13
  • I'll try rendering a `.js.erb` instead of a `.html.erb`. Thing is, it strikes me I'll have the same problem if I use an `erb` statement to try to render a separate partial that contains javascript. – sscirrus Apr 29 '13 at 06:33