开发者

Using youtube_it gem in rails 3.1

开发者 https://www.devze.com 2023-03-31 19:46 出处:网络
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

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开发者_C百科 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:

<iframe width="560" height="345" src="http://www.youtube.com/embed/zrVL81FC77w" frameborder="0" allowfullscreen></iframe>

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.


Here is a rails app that has example youtube_it code in it.

https://github.com/chebyte/youtube_it_rails_app_example

0

精彩评论

暂无评论...
验证码 换一张
取 消