How should I start this Ruby on Rails app?
I want to create an app in Ruby on Rails that when a user pastes the link of a video, the thumbnail is embedded, and when the user clicks the thumbnail, the video is embedded with ajax. How should I start developing this functionality? I plan on using Embedly. My first question is how do I use it? I've read the documentation, but there are a bunch of different tutorials and I'm not sure which one to use. And specifically how do I get the thumbnail and the video? Also, should I have a sepa开发者_如何转开发rate model for both the thumbnail and the video? Or should the thumbnail be a field in the video table? What should I be storing in my database?
I would really, really appreciate any help.
Embed.ly API gives you a pretty wide range of options. Thumbnail is also included in the return hash. All you need to do is capture the url your users paste, plug it into this API url, and parse the returned hash for the thumbnail image.
You can then easily use the jQuery plugin to generate the embed link when the user clicks on the thumbnail.
$.embedly('http://www.youtube.com/watch?v=LfamTmY5REw',
{maxWidth: 600,
elems: $('#element'),
success: function(oembed, dict){
alert(oembed.title);
});
Note that in this function elems property is where you want your video to be embedded. oembed parameter contains the hash, which includes the thumbnail image link. So you can do everything in this one call. Embed the video as soon as the user pastes the link, and simply hide the embedded video until the user interacts with the thumbnail image.
You should probably save the thumbnail url as a field of the same model as everything else.
精彩评论