Ruby-on-rails – Embed Youtube Video into Rails App

ruby-on-railsyoutube

When I put

<iframe width="560" height="349" src="<%= @video.link %>"></iframe>

Everything shows up fine. But the actual video won't play.. what am I doing wrong?

<iframe width="560" height="349" src="http://youtu.be/PF9-lstnLvo">
  <html lang="en" dir="ltr">
 </iframe>

HELP!!

Best Solution

Wrong src at iframe, it need to be like:

http://www.youtube.com/embed/PF9-lstnLvo

You need to add code:string to you Video model.

Or method code, which return you this code from @video.link like this:

def code
  self.link.split('/').last if self.link
end

And replace erb:

<iframe width="560" height="349" src="<%= "http://www.youtube.com/embed/"+@video.code %>"></iframe>