Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么这段代码不起作用?
<%= truncate(post.text, :length => post.text.rindex(".", 500)) %>
我需要在第 500 个符号之前修剪最后一个点上的文本。
使用该:separator选项。它将在 500 个字符之前的点处截断
:separator
truncate(post.text, :length => 500, :separator => '.')