Joe Z
Joe Z

Reputation: 306

Spaces inserted in browser in <pre> with Rails

A simple test case: <% content = "<pre>a\nb</pre>" %> <%= raw content %>

Browser Screenshot, with inserted spaces on second line:

enter image description here

Here's where it gets interesting. In rails: raw(content).size # => 14 (correct)

But, in JS: $("pre").html().length // => 13 (should be 3)

Upvotes: 0

Views: 70

Answers (1)

Philip Hallstrom
Philip Hallstrom

Reputation: 19889

Any chance you are using HAML for your layout? If so, that would explain it as HAML will indent things for you. You can use HAML's ~ to get around this.

See: http://haml.info/docs/yardoc/file.REFERENCE.html#tilde

Upvotes: 1

Related Questions