The escape_javascript method in ActionView escapes the apostrophe \'
as backslash apostrophe \\\'
, which gives errors when parsing as JSON.
For
Already there is an issue in github/rails https://github.com/rails/rails/issues/8844
Fix to mark the string as html_safe
<%= escape_javascript("I'm here".html_safe) %>
or even better you can sanitize the string
<%= sanitize(escape_javascript("I'm here")) %>
<%= escape_javascript(sanitize("I'm here")) %>