Created
March 28, 2013 19:56
-
-
Save Myhka/5266296 to your computer and use it in GitHub Desktop.
Youtube helper method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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