Skip to content

Instantly share code, notes, and snippets.

@Myhka
Created March 28, 2013 19:56
Show Gist options
  • Save Myhka/5266296 to your computer and use it in GitHub Desktop.
Save Myhka/5266296 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment