添加'视频不受支持'消息到Rails video_tag

时间:2017-08-09 03:18:19

标签: ruby-on-rails ruby html5-video

有没有办法让这段代码有效?

= 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>

1 个答案:

答案 0 :(得分:1)

不,这是不可能的。您需要在模板中自行渲染:

<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')