3

I am trying to use Javascript to render an .html.erb partial that itself contains safe Javascript.

<%= render :partial => "tasks" %> fails to render anything.

<%= escape_javascript( render :partial => "tasks" ) %> renders the HTML but the javascript is escaped, so it doesn't work.

How can I get both the HTML and its embedded Javascript to render properly?

sscirrus
  • 55,407
  • 41
  • 135
  • 228

2 Answers2

0

If the issue with <%= escape_javascript( render :partial => "tasks" ) %> is that the line is being escaped then <%= raw escape_javascript( render :partial => "tasks" ) %> should fix that.

If you want to learn more check out this link. http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/

Btuman
  • 881
  • 2
  • 9
  • 37
-1

If the extension of the file is .js.erb then you can use <%= escape_javascript( render :partial => "tasks" ) %>,

Alternatively <%= escape_javascript( render "tasks" ) %>

Amit Thawait
  • 4,862
  • 2
  • 31
  • 25