Last active
December 29, 2022 20:56
-
-
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
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
#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