我简单的Ruby on Rails应用程序有些问题 [英] There's something really wrong with my simple Ruby on Rails app

查看:117
本文介绍了我简单的Ruby on Rails应用程序有些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在人们拒绝发布代码片段之前,我不会投票给我,让我告诉你我已经尝试了很多次,但人们似乎无法弄清楚什么是错误的。查看为什么jQuery代码不工作?这个jQuery隐藏功能只是不想工作的例子什么是不工作的。这是一个使用jQuery和嵌入式API的Ruby on Rails应用程序。奇怪的是,人们已经将完全相同的javascript和html代码复制到jsfiddle中,并且适用于他们。



我问是否有人可以退房这里的代码和它叉: https://github.com/meltzerj/Dreamstill 有人谁知道Ruby在Rails和jQuery上就足够了,并且可以计算出嵌入式API。根本没有太多的代码,所以它不应该是一个麻烦。我真的很感谢任何帮助让我走上正轨。谢谢。



哦,请不要犹豫,问我任何问题。 / div>



我已经提取了你的代码,我想(希望)如果我已经正确地确定了你的问题,我可能会为你提供一个解决方案。我在表单中粘贴了一个YouTube链接,并将其重定向到了 / videos / 1 ,其中有一个视频链接,随后由视频缩略图嵌入。



我看到它的问题是这样的:

  $(#video_div img)。click(function(){
$(div.embed)。toggle();
});

当文档就绪处理程序被调用时,文档中没有图像,所以您的 #video_div img 选择器无法找到任何内容。这可以通过使用 live() jQuery方法而不是 click() 文档。我将它更新为:

  $(#video_div img)。live('click',function(){
$(this).toggle();
$(div.embed)。toggle();
});

这似乎工作正常:点击时,缩略图消失,嵌入的视频出现。



希望有助于您指引正确的方向。


Before people vote me down for not posting code snippets, let me tell you that I have tried this many times, but people cannot seem to figure out what is wrong. Check out Why doesn't this jquery code work? and This jQuery hide function just does not want to work for examples of what is not working. It's a Ruby on Rails app using jQuery and the embedly API. The weird thing is that people have been copying the exact same javascript and html code into a jsfiddle and it works for them.

I'm asking if someone could please check out the code here and fork it: https://github.com/meltzerj/Dreamstill Someone who knows Ruby on Rails and jQuery well enough, and can figure out the embedly API. There's really not a lot of code at all, so it shouldn't be that much of a hassle. I would truly appreciate any help to get me on the right track. Thanks.

Oh, and please don't hesitate to ask me any questions.

解决方案

I've pulled your code and I think (hope) I might have a solution for you, assuming I've correctly identified your issue.

I pasted a YouTube link in the form and was redirected to /videos/1, where there was a 'video' link, which was later replaced by embedly with the video's thumbnail.

The problem as I see it, is with this:

$("#video_div img").click(function() {
  $("div.embed").toggle();
});

When your document ready handler is called, there is no image in your document yet, so your #video_div img selector fails to find anything. This can be easily corrected by using the live() jQuery method, instead of click() documentation. I updated it to this:

$("#video_div img").live('click', function() {
  $(this).toggle();
  $("div.embed").toggle();
});

Which seemed to work fine: on click, the thumbnail disappeared and the embedded video appeared.

Hope that helps point you in the right direction.

这篇关于我简单的Ruby on Rails应用程序有些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆