When I'm saying:
%p= item.price + " dollars"
I'm getting
50  ;dollars
instead of having non-breakable space symbol.
How to insert this and another special symbols using HAML ?
When I'm saying:
%p= item.price + " dollars"
I'm getting
50  ;dollars
instead of having non-breakable space symbol.
How to insert this and another special symbols using HAML ?
How about
%p= item.price + " dollars".html_safe
Use !=
instead of =
See "Unescaping HTML" in the haml reference: http://haml.info/docs/yardoc/file.REFERENCE.html#unescaping_html
I tried using html_safe
in different ways, but none worked. Using \xa0
as suggested by ngn didn't work, either, but it got me to try the Unicode escape of the non-breaking space, which did work:
"FOO\u00a0BAR"
and .html_safe
isn't even needed (unless something else in the string needs that, of course).
The Ruby Programming Language, first edition, says: "In Ruby 1.9, double-quoted strings can include arbitrary Unicode escape characters with \u
escapes. In its simplest form, \u
is followed by exactly four hexadecimal digits ..."
The interpolation option:
%p= "#{item.price} dollars".html_safe
This answer is for a slightly different question but I found this question searching for it...
If you have a submit tag %input{ :type => "submit", :value => " dollars", :name => "very_contrived" }
even if you throw an html_safe
on the :value
it will not evaluate the html.
The solution is to use the rails helper... duh
= submit_tag " dollars".html_safe
this is pretty obvious but it tripped me up. Legacy code + rails upgrade = this kind of stuff :P
I prefer using the character itself with the escaped HTML method with most symbols other than the whitespace characters. That way i don't have to remember all the html codes. As for the whitespace characters i prefer to use CSS, this is a much cleaner way.
%p&= "#{item.price} $%&#*@"
You could use \xa0
in the string instead of
. 0xa0 is the ASCII code of the non-breaking space.