Embed youtube video in rails

不羁岁月 提交于 2019-12-03 04:05:54

you have forgotten to close a bracket

<%= video_tag( @video.url %>

should be

<%= video_tag( @video.url ) %>

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:

<iframe width="490" height="275" src="<%= url %>" frameborder="0" allowfullscreen></iframe>

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 - now just call this in your views with:

<%= youtube_video @video.url %>

This works ok for me

I got it, you forgot to use erb syntax. Try:

<iframe width="560" height="315" src= "<%= #{@video.url} %>" frameborder="0" allowfullscreen></iframe>

@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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!