有没有办法让这段代码有效?
= 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>
答案 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')