Skip to content

Instantly share code, notes, and snippets.

@rickyhaswifi
Last active December 29, 2022 20:56
Show Gist options
  • Save rickyhaswifi/f2ccdc2a1d4a0dc2fcd3321b3f8a0de9 to your computer and use it in GitHub Desktop.
Save rickyhaswifi/f2ccdc2a1d4a0dc2fcd3321b3f8a0de9 to your computer and use it in GitHub Desktop.
Youtube & Spotify Embedded Content for Rails - Place this in model to slice specific strings
#YOUTUBE
def youtube_id
youtube_id = self.modelkey
youtube_id.gsub("https://www.youtube.com/watch?v=", "")
end
#Call as @model.youtube_id
<iframe width="560" height="315" src="https://www.youtube.com/embed/<%= @.youtube_id %>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
#SPOTIFY
def spotify_id
spotify_id = self.modelkey
spotify_id.gsub("https://open.spotify.com/track/", "")
end
#Call as @model.spotify_id
<iframe src="https://open.spotify.com/embed/track/<%= @.spotify_id %>" width="300" height="380" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment