将'video not supported'消息添加到 Rails video_tag



有什么方法可以让这段代码工作吗?

= video_tag("#{video.mp4}", "#{video.ogv}", 'Your browser does not support the video tag.'

现在它只添加带有文本消息的新视频源,而不是像那样返回:

<video>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>

不,这是不可能的。您需要在模板中自行呈现它:

<video>
<source src="#{movie.mp4}" type="video/mp4">
<source src="#{movie.ogg}" type="video/ogg">
Your browser does not support the video tag.
</video>

或者构建一个帮手来为你做到这一点:

def video_tag_with_not_supported_text(*sources)
options = sources.extract_options!.symbolize_keys
sources.flatten!
content_tag(:video, options) do
safe_join (
sources.map { |source| tag('source', :src => path_to_video(source)) } +
['Your browser does not support the video tag.']
)
end
end

然后像这样使用它:

=video_tag_with_not_supported_text('/x.mp4', '/y.ogv', width: '800px')

最新更新