I’m working on a simple rails project where I can create a post. My post model has a field for youtube video url so that when I create a post with the youtube video url, in the show page of the post the video would be embedded automatically and the users can watch the video from my web app due to the youtube video url provided.
I am trying to accomplish this with the youtube_it gem but I don’t know how to go about this. Any brief code sample in making this possible. Thanks
Why are you trying to use the Youtube API? I would just search the user-supplied url for the ID string that identifies the video, then insert that in to a template for embedding youtube videos on pages.
The HTML embed code for a video looks like this:
So just replace the zrVL81FC77w with the ID of the user’s video.
If you want to, you can probably check if the video exists by doing an HTTP request to YouTube from your server, but that is not necessary for what you are trying to do.