【问题标题】:Video HTML tag not showing in Rails视频 HTML 标记未在 Rails 中显示
【发布时间】:2020-07-31 11:14:25
【问题描述】:

当我在 _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 %>

【问题讨论】:

    标签: ruby-on-rails amazon-s3 html5-video rails-activestorage actiontext


    【解决方案1】:

    我在这篇文章的帮助下解决了我的问题: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
    

    【讨论】:

    • 这是rails 6.0.1 的正确答案,但是在rails 6.0.3 这没有帮助
    • 在 Rails 6.0.3.4 上为我工作。 ?
    猜你喜欢
    • 1970-01-01
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多