我正在使用Trix编辑器与上传附件功能。
目前我可以上传图片,pdf,视频等。并在提交后显示它们。我也可以有一个我上传的图像预览。
但我不知道怎么给它加个视频播放器。
我的实际_blob.html.erb如下所示:
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
<% if blob.representable? %>
<%= image_tag blob.representation(resize_to_fit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
<% end %>
<figcaption class="attachment__caption flex-1">
<div>
<% if caption = blob.try(:caption) %>
<%= caption %>
<% else %>
<span class="attachment__name text-gray-600"><%= blob.filename %></span>
<span class="attachment__size text-gray-600"><%= number_to_human_size blob.byte_size %></span>
<% end %>
</div>
<div class="mt-6 mb-4">
<%= link_to "View file", rails_blob_url(blob, disposition: "preview"), target: "_blank", class: "bg-gray-200 text-sm py-2 px-4 rounded mt-6" %> -
<%= link_to "Download", rails_blob_path(blob, disposition: "attachment"), class: " text-sm bg-gray-200 py-2 px-4 rounded" %>
</div>
</figcaption>
</figure>发布于 2020-05-19 07:33:18
在您的_blob中:
- if blob.video?
%video(controls="true" width="100%" preload="metadata")
%source{src: rails_blob_url(blob), type:"#{blob.content_type}"}%video为HTML5视频标签
接下来,您需要将以下代码添加到application.rb:
#video previews for action_text
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 'audio'
ActionText::ContentHelper.allowed_tags.add 'source'
end上述方法适用于rails 6.0.1,但可能不适用于rails 6.0.3
https://stackoverflow.com/questions/61441561
复制相似问题