I need to render this string that is stored in db:
<span style=\"color: #333333; font-family: 'Open Sans', Helvetica, Arial, sans-serif; font-size: 24px; line-height: 40px;\">Potentiometer</span>
When I try to assign it to a var like this:
var description:"<%= s.html_safe %>";
I get this error near 'Open Sans'
:
Uncaught SyntaxError: Unexpected identifier
Although I used '
not "
at var description:"<%= s.html_safe %>";
the resulted javascript will look like:
var description= '<span style=\"color: #333333; font-family: 'Open Sans', Helvetica, Arial, sans-serif; font-size: 24px; line-height: 40px;\">Potentiometer</span>';
This will cause an error as string starts with '
and it has '
too
Can someone help?
EDIT
The solution found is to use gsub and replace each '
with "
<%- s= raw(s.gsub(/'/, "\"")) %>
$scope.circuits.unshift({circuit:"<%= @experiment.circuit %>", description:'<%=s%>'});