[英]how can I eliminate the html tags generated along with the content in the view page, written using the Action text(trix Editor)?
我在 Rails 應用程序中安裝了動作文本(Trix 編輯器)。
寫入內容后,內容與html標簽一起生成。 例如
"div class="trix-content"> div> This is the content part. br>br> /div>
為此有一個內置函數:
content.to_plain_text
如果您想刪除圍繞您的內容的<div class="trix-content">
,並且不能依賴覆蓋views/layouts/action_text/contents/_content.html.erb
,您可以非常直率地通過正則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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.