I have a .js.erb file that renders a Ruby partial. Right now, everything works fine, and the first line is
<%# encoding: utf-8 %>
Later on when I add the line
$("#name").text("Name ▼");
Things still work, but the Unicode comes out as the code, not as the character I wanted. When I replace the above with
$("#name").text("Name " + ▼);
The partial just refuses to render. My Ruby console even lies by saying
Rendered interface/_tan.erb (5.5ms)
Rendered interface/tan_complete.js.erb (20.0ms)
Why is this happening?
You appear to be using jQuery. Try this instead:
The
.text()method sets theinnerTextproperty. The.html()method sets theinnerHTMLproperty. HTML entities render as plain-text when injected into theinnerTextproperty.As for why
$("#name").text("Name " + ▼);fails to render, I’m fairly sure that the&has a special significance in Ruby syntax (though I’m far from an expert) and that the#starts a comment, so the line is likely to be syntactically incorrect, thus causing an error which makes the partial fail to render.