Submitted by swarut on Tue, 07/03/2012 - 15:12 This can be done using escape_javascript method (aliased with j() ). $(".comments").html("<%= escape_javascript(@comment.discussion.nested_comments) %>");