在 Rails 中嵌入 YouTube 视频
我正在尝试将视频嵌入页面中。我尝试了两种不同的方法,但没有成功
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 %>
该视频不显示,其下面的链接也不显示。
任何提示将不胜感激。谢谢
这是调试结果
视频中的 ActionView::MissingTemplate#show
显示中 /Users/atbyrd/Documents/sites/city/app/views/videos/show.html.erb 第 15 行提出的位置:
缺少部分共享/视频:{:handlers=>[:erb, :builder, :咖啡], :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/views”
提取的源代码(大约第 15 行):
12: 13:
14: <% #video_tag( @video.url , :size => "560x315", :控制=> true, :autobuffer =>正确)%> 15: <%= youtube_video @video.url%> 16:
17: 18: <%= link_to '编辑', edit_video_path(@video) %> |Rails.root:/Users/atbyrd/Documents/sites/city 应用程序跟踪 | 框架跟踪 |完整跟踪
app/helpers/application_helper.rb:4:in
youtube_video' 应用程序/视图/视频/show.html.erb:15:in
_app_views_videos_show_html_erb__1532956397246631491_70281299458880' app/controllers/videos_controller.rb:18:在“显示”
I'm trying to embed video in pages. I tried two different ways but no luck
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
this is the debug result
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 Traceapp/helpers/application_helper.rb:4:in
youtube_video'
_app_views_videos_show_html_erb__1532956397246631491_70281299458880'
app/views/videos/show.html.erb:15:in
app/controllers/videos_controller.rb:18:in `show'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您忘记关闭括号
应该
更新:
尝试使用video_path而不是 video_tag。
第二次更新:
这是我自己在自己的网站上执行此操作的方法:
1 - 创建一个名为 _video.html.erb 的部分(我实际上使用haml,但如果您愿意,erb 也可以)并将其放在像 views/shared 这样的文件夹中,或者将以下代码放入其中:
2 将以下方法添加到 application_helper.rb
3 - 现在只需在您的视图中调用它即可:
这对我来说没问题
you have forgotten to close a bracket
should be
UPDATE:
Try using video_path instead of video_tag.
2nd UPDATE:
here's how I do this myself on my own site:
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:
2 add the following method to application_helper.rb
3 - now just call this in your views with:
This works ok for me
我明白了,你忘了使用 erb 语法。尝试:
I got it, you forgot to use erb syntax. Try:
@miaout17是对的,你不能在HTML中使用字符串插值,所以你必须将它包装在Erb中(例如<%= %>)。
另外,您在下面的链接中缺少结尾“)”,这可能就是它们不起作用的原因。
@miaout17 is right, you can't use string interpolation in HTML, so you have to wrap it in Erb (e.g. <%= %>).
Also you're missing an ending ')' in your links below which is probably why they aren't working.