【问题标题】:ActionText blob partial not rendering extra elementsActionText blob 部分不呈现额外元素
【发布时间】:2020-03-20 00:27:27
【问题描述】:

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

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

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

/views/active_storage/blob/_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>

【问题讨论】:

    标签: ruby-on-rails rails-activestorage actiontext


    【解决方案1】:

    我发现问题在于使用内部方法在渲染之前清理字符串的动作文本。

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

    ActionText::ContentHelper.allowed_attributes.add 'style'
    ActionText::ContentHelper.allowed_attributes.add 'controls'
    
    ActionText::ContentHelper.allowed_tags.add 'video'
    ActionText::ContentHelper.allowed_tags.add 'source'
    

    【讨论】:

      【解决方案2】:

      在我的例子中,当我在 _blob.html.erb 中将自定义属性 (data-) 添加到 link_to 助手时,它没有包含在呈现的链接标记中。

      <% if blob.representable? %>
        <%= link_to image_tag(blob.representation(resize_to_limit: 
      local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]), 
      class: 'rounded'), rails_blob_path(blob), { 'data-fancybox': 'gallery' } %>
      <% end %>
      

      【讨论】:

        【解决方案3】:

        我想知道如何在 _blob.html.erb 文件中获取 action_name。 因为我想根据动作名称显示或关闭图像链接,例如showedit

        【讨论】:

          【解决方案4】:
          # config/initializers/html_sanitation.rb
          
          Rails::Html::WhiteListSanitizer.allowed_tags << 'h2'
          

          【讨论】:

            猜你喜欢
            • 2020-07-08
            • 2016-10-26
            • 1970-01-01
            • 2018-08-30
            • 1970-01-01
            • 2013-11-07
            • 2014-11-24
            • 1970-01-01
            • 2023-03-05
            相关资源
            最近更新 更多