Reputation: 107
I have tried to display an youtube embedded iframe of a link (that a user would input and save in a form)
The embedded video doesnt show up. All i get is blank space.
Here is my code
<iframe width="560" height="315" src= "<%= video.link %>" frameborder="1" allowfullscreen></iframe>
I have checked the source code
screenshot here http://screencast.com/t/gmQAiFHEj
In the source you can see it displaying the URLS of the youtube videos but how can i get it render?
Upvotes: 1
Views: 1560
Reputation: 5330
Deefour is right. I am posting an answer just to show you a better way to display youtube videos (it is going to be easier for you)
Create a partial _youtube.html.erb and paste:
<iframe width="490" height="275" src="<%= url %>" frameborder="0" allowfullscreen></iframe>
Then add in you Application controller:
module ApplicationHelper
def youtube_video(url)
render :partial => 'shared/youtube', :locals => { :url => url }
end
end
And then in your views call:
<%= youtube_video @video.url %>
But yes, try not to copy wrong link, use, links like:
"http://www.youtube.com/embed/NWHfY_lvKIQ"
Upvotes: 3
Reputation: 35360
The YouTube URL you're using is not a proper embed URL.
YouTube blocks direct embed requests when using the direct URL to the YouTube page.
See the example below showing the difference (the above Right URL works fine).
Upvotes: 7