I would like to output a string from a helper like ’30 Meters2′ (but with a superscript 2).
The HTML entity for a superscript 2 is ² so I thought something like this would work:
"30 Meters " + raw("²")
But it doesn’t work.
How can I do this?
Here’s the entire method:
def area_conversion(feet, project)
if project.metric
"#{(feet * 0.0929).round} Meters" + raw("²")
else
"#{feet} sq. ft. "
end
end
Using html_safe doens’t seem to work either:
def area_conversion(feet, project)
if project.metric
"#{(feet * 0.0929).round} Meters" + "²".html_safe
else
"#{feet} sq. ft. "
end
end
I think you need to declare the whole string as
html_safebecause a safe string merged with a unsafe string gets unsafe again. In your case it should be save because a string multiplied by a float is empty, so nobody can not put dangerous code into your string here.So this:
should be fine.