Rails 6中ActionText显示携带HTML标签问题求助
Action Text 显示HTML标签问题求助
我找了很多地方都没找到解决方案,只见过一个类似问题的帖子。尝试用sanitize方法时出现错误:no implicit conversion of ActionText::RichText into String,现在想先解决HTML标签直接显示的原始问题,当前显示效果如下:

以下是我已经完成的配置:
- 在Comment模型中添加了
has_rich_text:
class Comment < ApplicationRecord belongs_to :user belongs_to :post validates :body, presence: true, allow_blank: false has_rich_text :body end
- 在application.js中添加导入:
import "trix" import "@rails/actiontext"
- 在actiontext.scss中添加导入:
@import "trix/dist/trix";
- 在application.css.scss中添加导入:
@import "./actiontext.scss";
- 在表单中添加了富文本区域:
<%= form_with model: [@post, @comment], local: true do |f| %> <%= f.rich_text_area :body, class: 'form-control greyh' %> <%= f.submit 'Comment', class: 'btn btn-success' %> <% end %>
- 当前使用的显示代码:
<%="[#{comment.created_at.strftime("%I :%M %p")}] #{comment.user.username}: #{comment.body}" %>
现在我实在不知道还能尝试什么方法,恳请大家帮忙解决。
内容的提问来源于stack exchange,提问作者user2023608
相关产品推荐
相关产品推荐

