Created
February 26, 2014 19:04
-
-
Save ssaunier/9236175 to your computer and use it in GitHub Desktop.
Youtube embed video Helper
This file contains 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
require "uri" | |
require "cgi" | |
class ApplicationHelper | |
def embedded_video(url, options = {}) | |
if url | |
# TODO: Handle other sources than Youtube video | |
params = CGI::parse(URI.parse(url).query || "") | |
if params["v"] | |
embedded_url = "//www.youtube.com/embed/#{params["v"].first}" | |
content_tag :iframe, nil, options.merge(src: embedded_url) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment