2

当我在 _blob.html.erb 中预览 blob 时,我可以预览图像,但我在嵌入视频时遇到了困难。以下<video>标签未显示在网页中。

如果我运行该blob.service_url函数并将其输出粘贴到行中的位置<source src="<%= blob.service_url %>" type="video/mp4">,然后手动将视频标签粘贴到 Chrome HTML 中,视频播放器会按我的意愿出现,但我不知道为什么视频标签会'不直接从 erb.html 文件编译。有谁知道为什么标签不呈现?

  <% if blob.representable? %>
    <% if blob.video? %>
      <video width="1024" height="768" controls>
        <source src="<%= blob.service_url %>" type="video/mp4">
      </video>
      <%= blob.service_url %>
    <% else %>
      <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
    <% end %>
  <% end %>
4

1 回答 1

2

我在这篇文章的帮助下解决了我的问题:https ://github.com/rails/rails/issues/36725 。

事实证明,我需要修改我的配置,因为默认情况下不允许使用各种标签。在 application.rb 中,我需要添加:

config.after_initialize do
  ActionText::ContentHelper.allowed_attributes.add 'style'
  ActionText::ContentHelper.allowed_attributes.add 'controls'

  ActionText::ContentHelper.allowed_tags.add 'video'
  ActionText::ContentHelper.allowed_tags.add 'source'
end
于 2020-04-17T21:06:26.907 回答