我需要做什么/检查我的rails 3项目中是否安装了jQuery(What do I need to do/check to see if jQuery is installed in my rail

编程入门 行业动态 更新时间:2024-10-26 08:30:13
我需要做什么/检查我的rails 3项目中是否安装了jQuery(What do I need to do/check to see if jQuery is installed in my rails 3 project)

我怎么知道/检查我的rails项目中是否安装了jQuery? 我正在编写一些jQuery代码,并希望确保我已正确安装必备组件。 我知道有一个宝石可以做到这一点,但我想知道是否有人可以指出一种方法来安装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可以自动在您的应用程序中使用而无需您进一步干预,您可以通过在视图中添加以下内容来验证:

<script type='text/javascript'> $('#mydiv').show(); </script> <div id='mydiv' style='display:none'> TEST </div>

如果在加载该视图页面时看到TEST,则jquery正在运行。

如果你看一下app / assets / javascripst / application.js,你会看到jquery.js包含在那个清单中,rails会把它加载到你的所有页面上。 如果从该文件中删除jquery.js,则不会加载它。 如果你想这样做,(没有真正的原因??),那么你可以下载你想要的jquery.js版本,把它贴在'public / javascripts'中,然后放

<%= javascript_include_tag 'jquery.js' %>

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

app / assets / javascripts是新的首选方式,因为它使用了新的资产管道功能,但旧的方法,将它们放在'public / javascripts'中仍然有效。

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>

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

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' %>

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

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.

更多推荐

本文发布于:2023-08-03 23:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405202.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:做什么   项目   安装了   rails   project

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!