I'd like to make the omission "..." a link for my truncated ruby string. Here's what I have:
<%= truncate(testimony.testimony, :length => 125, :omission => (link_to "...", testimony)) %><br />
but it does this:
Etiam porta sem malesuada magna mollis euismod. Aenean lacinia bibendum nulla sed consectetur<a href="/testimonies/1">...</a>
Rather than making the actual ... a link it shows the code. See: http://cl.ly/4Wy3 for the screenshot.
Thanks!
The problem is that truncate santizes the output , you need to use raw()
as in the docs below:
The result is not marked as HTML-safe, so will be subject to the default escaping when used in views, unless wrapped by raw(). Care should be taken if text contains HTML tags or entities, because truncation may produce invalid HTML (such as unbalanced or incomplete tags).
EDIT example:
<%= raw(truncate(testimony.testimony, :length => 125, :omission => (link_to "...", testimony))) %><br />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With