将YouTubevideo嵌入导轨中
我正试图在页面中嵌入video。 我尝试了两种不同的方法,但没有运气
show.html.erb
Name:
Url:
"560x315", :controls => true, :autobuffer => true ) %>
|
该video未显示其下方的链接。
任何提示将不胜感激。 谢谢
这是调试结果
video#show中的ActionView :: MissingTemplate
显示/Users/atbyrd/Documents/sites/city/app/views/videos/show.html.erb,其中第15行引发:
缺少部分共享/video{:handlers => [:erb,:builder,:coffee],:formats => [:html],:locale => [:en,:en]}。 搜索范围:*“/ Users / atbyrd / Documents / sites / city / app / views”*“/Users/atbyrd/.rvm/gems/ruby-1.9.2-p290/gems/devise-1.5.1/app/意见”
提取的来源(第15行):
12:13:
14:“560×315”,:controls => true,:autobuffer => true)%> 15: 16:
17:18: |
Rails.root:/ Users / atbyrd / Documents / sites / city应用程序跟踪| 框架跟踪| 完整跟踪
app / helpers / application_helper.rb:4:在
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这样的文件夹中或者广告中放入以下代码:
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 – 现在只需在您的视图中调用此方法:
<%= youtube_video @video.url %>
这对我来说没问题
我明白了,你忘了使用erb语法。 尝试:
@ miaout17是对的,你不能在HTML中使用字符串插值,所以你必须将它包装在Erb中(例如<%=%>)。
此外,您在下面的链接中错过了一个结尾’)’,这可能就是他们无法正常工作的原因。