我正在尝试在页面中嵌入视频。我尝试了两种不同的方法,但没有成功
显示.html.erb
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @video.name %>
</p>
<p>
<b>Url:</b>
<%= @video.url %>
</p>
<p>
<% #video_tag( @video.url , :size => "560x315", :controls => true, :autobuffer => true ) %>
<%= youtube_video @video.url%>
</p>
<%= link_to 'Edit', edit_video_path(@video) %> |
<%= link_to 'Back', videos_path %>
视频不显示,下面的链接也不显示。
如有任何提示,我们将不胜感激。谢谢
这是调试结果
ActionView::MissingTemplate in Videos#show
Showing /Users/atbyrd/Documents/sites/city/app/views/videos/show.html.erb where line #15 raised:
Missing partial shared/video with {:handlers=>[:erb, :builder, :coffee], :formats=>[:html], :locale=>[:en, :en]}. Searched in: * "/Users/atbyrd/Documents/sites/city/app/views" * "/Users/atbyrd/.rvm/gems/ruby-1.9.2-p290/gems/devise-1.5.1/app/views"
Extracted source (around line #15):
12: 13:
14: <% #video_tag( @video.url , :size => "560x315", :controls => true, :autobuffer => true ) %> 15: <%= youtube_video @video.url%> 16:
17: 18: <%= link_to 'Edit', edit_video_path(@video) %> |Rails.root: /Users/atbyrd/Documents/sites/city Application Trace | Framework Trace | Full Trace
app/helpers/application_helper.rb:4:in
youtube_video' app/views/videos/show.html.erb:15:in
_app_views_videos_show_html_erb__1532956397246631491_70281299458880' app/controllers/videos_controller.rb:18:in `show'
最佳答案
你忘了关闭括号
<%= video_tag( @video.url %>
应该是
<%= video_tag( @video.url ) %>
更新:
尝试使用 video_path而不是 video_tag。
第二次更新:
这是我在自己的网站上自己做的:
1 - 创建一个名为 _video.html.erb 的部分(我实际上使用的是 haml,但如果你愿意,erb 也可以)并将其放入 views/shared 之类的文件夹中,或者将以下代码放入其中:
<iframe width="490" height="275" src="<%= url %>" frameborder="0" allowfullscreen></iframe>
2 在application_helper.rb中添加如下方法
module ApplicationHelper
# this method will embed the code from the partial
def youtube_video(url)
render :partial => 'shared/video', :locals => { :url => url }
end
end
3 - 现在只需在您的 View 中调用它:
<%= youtube_video @video.url %>
这对我来说没问题
关于ruby-on-rails - 在 rails 中嵌入 youtube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8272026/