I'm trying to dynamically generate a tooltip. I have a variable @x
which I want to print in the tooltip, but I also want a linebreak. If @x == 2, then I want the tooltip to print like this:
(2)
Comments
The line break works when I'm only printing straight html. But when I add @x
, the line break stops working, and it all prints in one line. Here's the code I have:
<%= link_to "hover-me", "#", title:"(" + @x + ") Comments" %>
which prints this:
(2) Comments
Does anyone know why adding @x
removes the line break, or how I can remedy this?
<%= link_to "hover-me", "#", title: "(#{@x}) Comments".html_safe %>
The string needs to be marked as safe HTML, using html_safe
. I also changed your string concatenation to use interpolation, which may be preferred.