由于某种原因,rails 没有正确地转义 javascript 的 text_areas。我在导致无效 javascript 的文本区域周围出现换行符。我正在使用 HAML 和 formtastic,但我认为 escape_javascript 方法在 HAML 完成后处理了输出。这真是令人沮丧。请帮忙...
例子:
编辑.js.erb:
$('#ajax-form').html("<%= escape_javascript render 'form' %>")
_form.html.haml
= semantic_form_for @note do |f|
= f.input :body, as: :text
结果:
$('#ajax-form').html("<form id=\"edit_note\" action=\"/notes/123\" data-method=\"put\">\n<textarea name=\"note[body]\">
This is the note body </textarea>")
注意字面上的新行,这不应该发生!