In the .to_sentence method, How can I get the last_word_connector to output an HTML string?
For example:
locations.to_sentence last_word_connector: '<br />'
I want the <br /> to actually be interpreted. I have tried adding .html_safe on the end but to no avail.
You’ll need to tell the view that the string is “safe” to insert (i.e. it should be inserted as-is – not escaped):
The
html_safemethod returns a string that’s marked as, well, html-safe. So it won’t be escaped.Use with caution. The reason Rails escapes string by default is that it makes html- and javascript-injection attempts harmless. So if you’re not completely sure of the content of
locations, then be careful.