我正在使用 youtube_it gem 将精选的 YouTube 视频加载到我的网站上,它在开发中运行良好,但是当部署到 prod 时,我在 Chrome 控制台中收到混合内容错误,因为视频在我的 上以 HTTP 的形式通过HTTPS 领域。
我不知道如何更改 embed_html5 删除协议(protocol)的方法。
这是我的代码
@latest_videos = yt_client.videos_by(:user => 'foobar').videos
<% @latest_videos.each do |video| %>
<%= raw video.embed_html5({width: '312', height: '240', frameborder: '0', fullscreen: true, modestbranding: "1"}) %>
<h4><%= video.title %></h4>
<% end%>
最佳答案
如果你看看embed_html5方法定义你会看到:
# File 'lib/youtube_it/model/video.rb', line 256
def embed_html5(params = {})
opts = {:class => params[:class] || "",
:id => params[:id] || "",
:width => params[:width] || "425",
:height => params[:height] || "350",
:protocol => params[:protocol] || "http",
:frameborder => params[:frameborder] || "0",
:url_params => params[:url_params] || {},
:sandbox => params[:sandbox] || false,
:fullscreen => params[:fullscreen] || false,
}
...
end
您必须通过
embed_html5
那protocol
值为 https
的选项,像这样:<%= raw video.embed_html5({protocol: 'https', width: '312', height: '240', frameborder: '0', fullscreen: true, modestbranding: "1"}) %>
这应该解决它!
关于ruby-on-rails - Rails 在安全站点上嵌入 youtube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28020715/