Search code examples
ruby-on-rails-3hamlformtastic

escape_javascript not properly escaping text_area's


For some reason rails is not properly escaping text_areas for javascript. I am getting line breaks around text areas which leads to invalid javascript. I am using HAML and formtastic, but I thought the escape_javascript method handled the output after HAML was done with it. This is really frustrating. Please help...

example:

edit.js.erb:

$('#ajax-form').html("<%= escape_javascript render 'form' %>")

_form.html.haml

= semantic_form_for @note do |f|
  = f.input :body, as: :text

Result:

$('#ajax-form').html("<form id=\"edit_note\" action=\"/notes/123\" data-method=\"put\">\n<textarea name=\"note[body]\">
This is the note body </textarea>")

Notice the literal new line, this shouldnt be happening!


Solution

  • It is actually a bug in Haml, upgrade to 3.1.6.rc.1 and you should be fine.