[Ruby] I tried calling YouTube video from DB with haml and embedding it

1 minute read

Method I found when I tried to embed a YouTube video with my own application

I wanted to save my favorite videos in the DB once by creating my own application and display them embedded when calling, so I will introduce various methods I searched for.

General embedding method

Choose where to share your favorite YouTube videos

Screenshot 2020-07-12 16.16.00.png

Further embed from there and choose the one  Screenshot 2020-07-12 16.16.33.png

Since the URL for embedding the video appears, click copy  Screenshot 2020-07-12 16.16.59.png

Complete by pasting this directly into HTML (haml)

The result looks like this Screenshot 2020-07-12 16.21.46.png

However, when I post it to the DB with this and when I try to call it from the haml file, it appears as a character string, so it is a method to solve it.

The way I actually went

%iframe#player{frameborder: "0", height:"390", src: (movie.url), type: "text/html", width: "640"}
*This time I made a movie model and set the column name to url

Put simply, ・The outer frame part should be a haml file (the size etc. can be changed as you like) ・ Only the URL part is saved in the DB → called ・Title and contents are saved in another column

By doing this, it was possible to embed it when posting to DB → calling.

Actual image (still under development)

Screenshot 2020-07-12 16.36.11.png ↑ I was able to successfully implement all posting functions (cracking)

One caution point

This is the URL I used, but this part is underlined in blue (no need for double quotes)  Screenshot 2020-07-12 16.38.35.png

 Screenshot 2020-07-12 16.16.33.png

This blue underlined URL didn’t work. Probably because it is not the URL for embedding.

I hope that it will be helpful for those who want to implement the same as above.