使用rails在javascript响应中呈现Haml文件

使用rails在javascript响应中呈现Haml文件,javascript,jquery,ruby-on-rails-3,haml,Javascript,Jquery,Ruby On Rails 3,Haml,我正在尝试以javascript响应呈现haml文件,如下所示: $('#<%= @email.unique_name %> .preview .mail_content').html('<%=j render( :file => "user_mailer/#{@email.key}") %>'); 现在,如果我们查看响应中给出的javascript,我会遇到两个问题: $('#launch_share_results .preview .mail_content

我正在尝试以javascript响应呈现haml文件,如下所示:

$('#<%= @email.unique_name %> .preview .mail_content').html('<%=j render( :file => "user_mailer/#{@email.key}") %>');
现在,如果我们查看响应中给出的javascript,我会遇到两个问题:

$('#launch_share_results .preview .mail_content').html('\u003Cp\u003EHi Jane,\u003C/p\u003E
\u003Cp\u003EJohn Smith has taken a 360(deg) \u003Cspan style=color:red;\u003E\u003Cstrong\u003ENo such variable available!\u003C/strong\u003E\u003C/span\u003E assessment through myLAUNCHtools.com and would like to share the results with you.\u003C/p\u003E
\u003Cp\u003EPlease click the link below to go directly to the results of John's assessment. You can also access an analysis of that assessment from that page.\u003C/p\u003E
\u003Cp\u003Ehttp://lvh.me:3000/assessments/results/1\u003C/p\u003E
\u003Cp\u003EThank you in advance for your time and interest in John\u0026#8217;s leadership.\u003C/p\u003E
\u003Cp\u003ESincerely,\u003Cbr /\u003E
Launch\u003C/p\u003E
');
主要的问题是反应中有新词。这破坏了请求。我认为在渲染调用之前使用j可以解决这个问题,但事实并非如此

另一个问题是,在haml文件的第三行,我有:

#{@user.first_name}'s assessment
这个撇号也破坏了请求。(我知道这一点,因为我使用了javascript函数删除了所有新行,请求仍然被中断,直到我也去掉了撇号)


有没有比链接javascript函数来清理javascript响应更简单的方法呢?

我遇到了类似的问题。问题的存在是因为“escape_javascript”和“json_escape”这两种方法的别名都是“j”(https://github.com/rails/rails/pull/3578)

解决方案:
使用“escape\u javascript”而不是“j”。

我遇到了类似的问题。问题的存在是因为“escape_javascript”和“json_escape”这两种方法的别名都是“j”(https://github.com/rails/rails/pull/3578)

解决方案: 使用“escape_javascript”而不是“j”

#{@user.first_name}'s assessment