9

Having finished Hartl's great Rails Tutorial I'm now working my way through the very good jQuery - Novice to Ninja by Castledine and Sharkie. While I've able to include jquery.js and jquery-ui.js in my rails projects, I'm getting stuck when it comes to adding other jQuery plugins.

I've figured out that when the plugins are hosted on github, I can import them into my project using the command line and:

[my rails app]$ rails install [github URL]

The plugin gets successfully imported into the /vendor/plugin/ directory where javascript_include_tag can't find them. This situation prompts 3 questions:

  1. Is there a way to import jQuery plugins into my Rails app that puts them into the public/javascripts/ directory where they belong?

  2. If the answer to 1 is "no," is there a way to have javascript_include_tag search for scripts in vendor/plugins/? This seems like bad practice since jQuery scripts are hidden away from the public/javascript/ directory where people would normally look for them.

  3. If 1 and 2 are both "no's," is there a more elegant way to move the files from vendor/plugins/ than $mv or copying and pasting?

Note: Through web searching I've come across 37signals' sprokets gem at http://getsprockets.org/ which seems like it might be useful at some point but beyond my current needs and understanding.

Grateful for any thoughts!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
BenU
  • 2,287
  • 1
  • 22
  • 35

3 Answers3

8

In current rails version the directory would be

/vendor/assets/javascripts
bento
  • 2,079
  • 1
  • 16
  • 13
  • This is now the correct place to put them if you're using the asset pipeline which is basically sprockets in rails with a bunch of added convenience and functionality (there's very little reason not to use it). Many jQuery plugins you can even include as a gem, and the asset pipeline will find the assets from the gem (see masonry-rails gem, for instance). A new development is talk about replacing those kind of asset library gems with Twitter's 'bower'. – mltsy Nov 07 '12 at 18:13
4

Normal practice is to download a minified version of the plugin you'd like to use and save it in the public/javascripts directory.

rails install is for Rails plugins, not jQuery plugins.

Fareesh Vijayarangam
  • 5,037
  • 4
  • 23
  • 18
  • Very cool. Both your answers helped me put what I've figured out into a wider context. – BenU Mar 21 '11 at 13:24
1

If you are insistent on using rails install you could write a rake or thor task to copy the files for you.

You could also try a symlink between the public/javascripts directory and the download directory so the stylesheet tag can just access it.

huntsfromshadow
  • 1,085
  • 8
  • 12