我正在尝试将视频嵌入页面中.我尝试了两种方法,但是没有运气
I'm trying to embed video in pages. I tried two different ways but no luck
show.html.erb
show.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 %>该视频未显示其下方的链接.
The video does not show neither does the links below it.
任何提示将不胜感激.谢谢
Any tips would be appreciated. Thank you
这是调试结果
Videos#show中的ActionView :: MissingTemplate
ActionView::MissingTemplate in Videos#show
显示 /Users/atbyrd/Documents/sites/city/app/views/videos/show.html.erb 第15行在哪里出现:
Showing /Users/atbyrd/Documents/sites/city/app/views/videos/show.html.erb where line #15 raised:
缺少与{:handlers => [:erb,:builder, :coffee] 、: formats => [:html] 、: locale => [:en,:en]}.搜索到:* "/用户/atbyrd/文档/站点/城市/应用/视图" * "/Users/atbyrd/.rvm/gems/ruby-1.9.2-p290/gems/devise-1.5.1/app/views"
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"
提取的来源(第15行附近):
Extracted source (around line #15):
12:13:
14:<%#video_tag(@ video.url,:size =>"560x315", :controls => true,:autobuffer => true)%> 15:<%= youtube_video @ video.url%> 16:
12: 13:
14: <% #video_tag( @video.url , :size => "560x315", :controls => true, :autobuffer => true ) %> 15: <%= youtube_video @video.url%> 16:
Rails.root:/Users/atbyrd/Documents/sites/city应用程序跟踪| 框架跟踪|完整跟踪
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:在显示"中
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.
Try using video_path instead of video_tag.
第二次更新:
这是我自己在自己的网站上执行的操作:
here's how I do this myself on my own site:
1-创建一个名为_video.html.erb的部分文件(我实际上使用haml,但是如果您喜欢erb可以使用erb),然后将其放置在诸如views/shared之类的文件夹中,或者在广告中放置以下代码:
1 - create a partial called _video.html.erb (I actually use haml, but erb will do if you prefer it) and put it in a folder like views/shared or something ad put the following code in it:
<iframe width="490" height="275" src="<%= url %>" frameborder="0" allowfullscreen></iframe>2将以下方法添加到application_helper.rb
2 add the following method to 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 end3-现在只需在您的视图中使用以下命令调用即可:
3 - now just call this in your views with:
<%= youtube_video @video.url %>这对我来说很好
更多推荐
将YouTube视频嵌入Rails中
发布评论