我怎么知道/检查我的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.
更多推荐
发布评论