views:

37

answers:

2

Dear experts,

I have an library of scripts I would like to implement on the client side of my rails application;

In the View, I know that I can do the following.

<%= javascript_include_tag 'folder/script.js' %>
..

And because there are so many separate script files, this process is very time wasting and redundant.

I know that there's a technique to include all scripts in the public/javascript folder

<%= javascript_include_tag :all %>

But this would include the unwanted scripts outside of the destination folder specifically for the one View.

Is there a way to only include all scripts in an specific folder?

Thanks in advance

+1  A: 

http://github.com/sbecker/asset_packager

This bundles all of your javascripts into one file in production and lists them separately in development. With one rake task you define all your javascripts and stylesheets, and the order you want them stored. Another task packages them into two files. Really cool.

mark
Asset packager (and others like Jammit) will also strip comments, minify your source etc. Definitely the way to go for an app in production. In development your scripts are loaded as usual.
Andy Atkinson
+1  A: 

You can use the standard javascript_include_tag along with the Dir.glob method to include all the files in a directory. So, something like this should work:

<%= javascript_include_tag Dir.chdir(File.join(Rails.root, "public", "javascripts", "your", "subdiretory")) { |d| Dir.glob("*.js") } %>
vegetables