动作文本 trix 不在 blob 局部渲染图像和其他 html 标记

Action text trix does not render image and other html tag inside the blob partial

我正在将带有操作文本和 Trix 富编辑器的应用程序迁移到 rails 6.1.4.4。在后端,Trix 将上传的文件保存到活动存储 blob 并在编辑器中完美显示。

然而,当我尝试在没有 Trix 的情况下在前端显示时,上传的图像没有按预期显示。

下面是我的 blob 视图

<!-- active_storage/blobs/_blob.html.erb -->
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
  <% if blob.representable? %>
    <% blog_url = blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 600, 400 ] : [ 400, 400 ]).processed.service_url %>
    <%= lazy_image(src: blog_url, alt: '', width: '400', height: '400') %>
  <% end %>

  <figcaption class="attachment__caption">
    <% if caption = blob.try(:caption) %>
      <%= caption %>
    <% else %>
      <span class="attachment__name"><%= blob.filename %></span>
      <span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
    <% end %>
  </figcaption>
</figure>

我也尝试了一些其他的html标签,似乎一些html标签被剥离了,只保留了标签内容而不是完整的语义标签。

我的 blob 渲染内容会被净化吗?我是否缺少任何配置来让显示器在没有 trix 编辑器的情况下工作?

我通过在 config/application.rb

中添加以下代码解决了这个问题
    # Sanitize image in blob
    tags = ['img', 'iframe']
    config.action_view.sanitized_allowed_tags = tags

    lazy_image_attrs = ['src', 'alt', 'data-src', 'data-srcset', 'width', 'height', 'class']
    config.action_view.sanitized_allowed_attributes.push(*lazy_image_attrs)