我想让省略号..."成为我截断的 ruby 字符串的链接.这是我所拥有的:
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 />但它是这样做的:
Etiam porta sem malesuada magna mollis euismod. Aenean lacinia bibendum nulla sed consectetur<a href="/testimonies/1">...</a>而不是制作实际的...链接,它显示了代码.请参阅:cl.ly/4Wy3 获取屏幕截图.
Rather than making the actual ... a link it shows the code. See: cl.ly/4Wy3 for the screenshot.
谢谢!
推荐答案问题是 truncate santizes 输出,您需要使用 raw() ,如下面的文档所示:
The problem is that truncate santizes the output , you need to use raw() as in the docs below:
结果未标记为 HTML 安全,因此在视图中使用时将受到默认转义的影响,除非由 raw() 包装.如果文本包含 HTML 标签或实体,则应小心,因为截断可能会产生无效的 HTML(例如不平衡或不完整的标签).
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).
编辑示例:
<%= raw(truncate(testimony.testimony, :length => 125, :omission => (link_to "...", testimony))) %><br />更多推荐
在 ruby 中省略截断链接
发布评论