如何在没有 trix 格式信息的情况下截断 ActionText 输出

Gre*_*reg 2 string ruby-on-rails actiontext

我有一个 Rails 操作文本字段:content,如果我接受整个字段,它会呈现良好,但它很长,我只想显示其中的一部分。

<%= year.content %>工作正常,除了太长。

<%= year.content.truncate(70) %>结果是undefined method 'truncate' for #<ActionText::RichText:0x00007ffb811a6060>

<%= year.content.to_s.truncate(70) %>显示<div class="trix-content"> <div> <strong>Jack Marietich, restaura...我可以使用的内容,但是有没有一种方法我不必删除开头?

Gre*_*reg 10

Trix使用rails actiontext添加纯html,它在我发布之后出现,但之前没有出现。

<%= year.content.to_plain_text.truncate(70) %>
Run Code Online (Sandbox Code Playgroud)

https://api.rubyonrails.org/classes/ActionText/RichText.html#method-i-to_plain_text但即使我找到了它,也不确定我是否会理解这就是我需要的。