Ant*_*yrd 2 embed youtube macos video ruby-on-rails
我正在尝试在页面中嵌入视频。我尝试了两种不同的方法,但没有运气
显示.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 %>
Run Code Online (Sandbox Code Playgroud)
视频不显示也不显示它下面的链接。
任何提示将不胜感激。谢谢
这是调试结果
ActionView::MissingTemplate 在视频中#show
显示第 15 行提出的 /Users/atbyrd/Documents/sites/city/app/views/videos/show.html.erb:
{: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: <% #video_tag( @video.url , :size => "560x315", :controls => true, :autobuffer => true ) %> 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' 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 %>
Run Code Online (Sandbox Code Playgroud)
应该
<%= video_tag( @video.url ) %>
Run Code Online (Sandbox Code Playgroud)
更新:
尝试使用video_path而不是 video_tag。
第二次更新:
这是我在自己的网站上自己执行此操作的方法:
1 - 创建一个名为 _video.html.erb 的部分(我实际上使用 haml,但如果你喜欢它,erb 也会这样做)并将它放在一个文件夹中,比如 views/shared 或一些广告,将以下代码放入其中:
<iframe width="490" height="275" src="<%= url %>" frameborder="0" allowfullscreen></iframe>
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
3 - 现在只需在您的视图中调用它:
<%= youtube_video @video.url %>
Run Code Online (Sandbox Code Playgroud)
这对我有用
归档时间: |
|
查看次数: |
6862 次 |
最近记录: |