但它是这样做的:-6ren">
gpt4 book ai didi

ruby-on-rails - 在 ruby​​ 中省略截断链接

转载 作者:数据小太阳 更新时间:2023-10-29 07:21:51 29 4
gpt4 key购买 nike

我想将省略的“...”作为我截断的 ruby​​ 字符串的链接。这是我拥有的:

  <%= 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>

与其创建实际的...链接,不如显示代码。请参阅:http://cl.ly/4Wy3用于屏幕截图。

谢谢!

最佳答案

问题是 truncate santizes 输出,您需要使用 raw(),如下面的文档所示:

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-on-rails - 在 ruby​​ 中省略截断链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4964073/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com