我需要做什么/检查以查看jQuery是否已安装在Rails 3项目中 [英] What do I need to do/check to see if jQuery is installed in my rails 3 project

查看:76
本文介绍了我需要做什么/检查以查看jQuery是否已安装在Rails 3项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何知道/检查我的rails项目中是否安装了jQuery?我正在编写一些jQuery代码,并希望确保正确安装了先决条件. 我意识到有一个gem可以做到这一点,但我想知道是否有人可以指出一种在没有gem的情况下安装带有gem的jQuery的方法.

How do I know/check whether I have jQuery installed in my rails project? I am writing some jQuery code and would like to ensure I have the prerequisites installed correctly. I realize there is a gem to do this but I was wondering if someone can point out a way to install jQuery with the gem and also without the gem.

推荐答案

在最新版本的Rails中,jquery可以自动在您的应用程序中使用,而无需您进行任何进一步的干预,您可以通过在视图中放入类似的内容来验证这一点. :

In the latest versions of rails, jquery is automagically available in your apps without any further intervention by you, you can verify this by putting something like this in a view:

 <script type='text/javascript'>
   $('#mydiv').show();
 </script>

 <div id='mydiv' style='display:none'>
   TEST
 </div>

如果在加载该视图页面时看到测试",则表明jQuery正在运行.

If you see TEST when you load that view page, jquery is functioning.

如果查看app/assets/javascripst/application.js,您会看到该清单中包含jquery.js,并且rails会将其加载到所有页面上.如果您从该文件中删除jquery.js,则不会加载该文件.如果您想这样做(没有真正的理由?),则可以下载所需的jquery.js版本,将其粘贴在"public/javascripts"中,然后放入

If you look at app/assets/javascripst/application.js, you'll see that jquery.js is included in that manifest, and rails will get it loaded on all your pages. If you delete jquery.js from that file, it won't be loaded. If you wanted to do that, (no real reason??), then you could download your desired version of jquery.js, stick it in 'public/javascripts', and put

<%= javascript_include_tag 'jquery.js' %>

或者您也可以将其放在app/assets/javascripts中,以上代码将加载它.

Or you could put it in app/assets/javascripts as well, and the above code will get it loaded.

app/assets/javascripts是新的首选方法,因为它利用了新的资产管道功能,但是将其置于"public/javascripts"中的旧方法仍然可以使用.

app/assets/javascripts is the new preferred way as it makes use of the new assets pipeline features, but the old method, putting them in 'public/javascripts' will still work.

这篇关于我需要做什么/检查以查看jQuery是否已安装在Rails 3项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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