banditKing banditKing - 5 months ago 27
jQuery Question

What do I need to do/check to see if jQuery is installed in my rails 3 project

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.


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

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

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.