Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does require jquery work in Rails 3 app?

In my rails 3 app it has:

//= require jquery
//= require jquery_ujs
//= require_tree .
//= require jquery-ui

And it works fine. But I don't understand how it works. I think I understand the third line which I believe adds everything to this file that is found in the same directory as this file (/app/assets/javascript). But what about the first line? Where does it get the jquery file? I don't see it in any of the directories it mentions in the comment at the beginning of the file, specifically:

// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.

Where does rails go to get the jquery javascript file?

like image 316
snowguy Avatar asked Jul 18 '12 05:07

snowguy


1 Answers

The require part you mentioned above is called asset pipeline, which is part of new features of rails 3. The goal of this is to concatenate all javascripts file together, so you have your page load faster by a single import of the javascript file.

You can find out more about asset pipeline here and if not mistaken it is utilizing sprockets gem.

Refering to //= require jquery, it is importing the javascript file from your jquery gem (only if you using jQuery gem). You can find it from your jQuery gem assets folder.

Refer this screencast as it described best.

Hope it helps.

like image 195
TonyTakeshi Avatar answered Oct 23 '22 00:10

TonyTakeshi