Skip to content

Instantly share code, notes, and snippets.

@ssaunier
Created February 26, 2014 19:04
Show Gist options
  • Save ssaunier/9236175 to your computer and use it in GitHub Desktop.
Save ssaunier/9236175 to your computer and use it in GitHub Desktop.
Youtube embed video Helper
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