0

On Rails 3.2.13, simple_format does not return what I expect it to do, on an admittedly convoluted case:

> simple_format("a <= 2, b < 4")
"<p>a &lt; 4</p>"

Since this case does not seem to work properly (I'm losing half my string!), is there a way to pre-escape special characters so that it works everywhere?

F.X.
  • 6,809
  • 3
  • 49
  • 71

1 Answers1

1

You could html_escape the string yourself:

ERB::Util.h("a <= 2, b < 4")
#=> "a &lt;= 2, b &lt; 4"

simple_format(ERB::Util.h("a <= 2, b < 4"))
#=> "<p>a &lt;= 2, b &lt; 4</p>"

From within views, you can omit ERB::Util. and just call h

Stefan
  • 109,145
  • 14
  • 143
  • 218
  • Ah, thanks, I found références to `h` everywhere, but ActiveAdmin pages don't work with views! – F.X. Feb 05 '15 at 10:42