ruby-on-rails - ActionText blob 部分不渲染额外元素

标签 ruby-on-rails rails-activestorage actiontext

我正在使用 ActionText 渲染一些富文本,由于某种原因,我在使用 actiontext 提供的部分向渲染的部分添加额外元素时受到限制

我需要将附加图像包裹在表格元素周围,以便可以在 Outlook 中为电子邮件正确呈现它们。 ActionText 似乎总是忽略我放入的这部分中的任何额外元素。有人知道为什么会发生这种情况以及是否有任何方法可以解决此问题?

这是我的部分,其中表格元素被忽略:

/views/active_storage/blobs/_blob.html.erb

<table>
  <Tr>
    <td>
      <figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %> text-center">
        <% if blob.representable? %>
          <%= image_tag rails_representation_url(blob.representation(resize_to_limit: [600, 400])) %>

          <% if caption = blob.try(:caption) %>
            <figcaption class="attachment__caption text-center">
              <%= caption %>
            </figcaption>
          <% end %>
        <% end %>
      </figure>
    </td>
  </Tr>
</table>

最佳答案

我发现问题与 Action Text 使用内部方法在渲染之前清理字符串有关。

我覆盖初始化程序中允许的属性和标签:

ActionText::ContentHelper.allowed_attributes.add 'style'
ActionText::ContentHelper.allowed_attributes.add 'controls'

ActionText::ContentHelper.allowed_tags.add 'video'
ActionText::ContentHelper.allowed_tags.add 'source'

关于ruby-on-rails - ActionText blob 部分不渲染额外元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59019537/

相关文章:

ruby-on-rails - 当 Guard 在监视文件中运行规范时,Rspec/Capybara "feature"方法未定义,手动运行时有效

sql - 将 Rails 查询更改为纯 SQL

ruby-on-rails - 我应该在 Heroku Cedar 上使用 Thin 还是 Unicorn

ruby-on-rails - Ruby on Rails 事件存储中的 Joint_PDF 解析错误

ruby-on-rails - RSpec ActiveStorage:错误 ActiveRecord::RecordNotFound:找不到 ActiveStorage::Blob 为 'id'

amazon-s3 - Rails ActiveStorage 的谷歌云存储 CORS 问题

ruby-on-rails - 从相同的 SGID 加载 ActionText::Attachable 在恢复数据库后不再有效

ruby-on-rails - 为单个用户验证 Ruby on Rails 中的唯一项目名称

javascript - Action 文本 (Trix) 样式不会在生产中加载(Rails 6、Heroku)

ruby-on-rails - 将按钮添加到 Rails ActionText 工具栏