将YouTube视频嵌入Rails中

编程入门 行业动态 更新时间:2024-10-13 10:30:42
本文介绍了将YouTube视频嵌入Rails中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将视频嵌入页面中.我尝试了两种方法,但是没有运气

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 end

3-现在只需在您的视图中使用以下命令调用即可:

3 - now just call this in your views with:

<%= youtube_video @video.url %>

这对我来说很好

更多推荐

将YouTube视频嵌入Rails中

本文发布于:2023-11-05 18:34:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561554.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视频   YouTube   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!