Skip to content

Instantly share code, notes, and snippets.

@Myhka
Myhka / gist:5266296
Created March 28, 2013 19:56
Youtube helper method
def youtube_embed(youtube_url, x, y)
if youtube_url[/youtu\.be\/([^\?]*)/]
youtube_id = $1
else
youtube_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
youtube_id = $5
end
%Q{<iframe title="YouTube video player" width=#{x} height=#{y} src="http://www.youtube.com/embed/#{ youtube_id }" frameborder="0" allowfullscreen></iframe>}
end