如何消除使用Action文本(trix编辑器)编写的与视图页面中的内容一起生成的html标签?

时间:2020-01-09 14:56:21

标签: html ruby-on-rails ruby wysiwyg trix

我在Rails应用程序中安装了Action文本(Trix编辑器)。

写入内容后,将与html标记一起生成内容。 例如

 "div class="trix-content"> div> This is the content part. br>br> /div>

2 个答案:

答案 0 :(得分:0)

有一个内置函数:

content.to_plain_text

答案 1 :(得分:0)

如果您想删除围绕您的内容的 <div class="trix-content">,并且不能依赖于覆盖 views/layouts/action_text/contents/_content.html.erb,那么您可以直截了当地使用正则表达式:

# Assuming your model uses `has_rich_text :content`
def contents
  content.to_s.gsub(/\A<div class="trix-content">(.*)<\/div>\z/m, '\1').strip.html_safe
end