0

Now I have more than 20 js libraries on my assets/javascript folder and my application.js is including all of them on every render but I just started to have some conflicts with one or two libraries....

My application.js looks like this:

//
//= require jquery
//= require jquery_ujs
//= require_tree .
// 

What I want to know is How can I call some libraries only on some controllers and some actions? and not load all of them on the entire application.

Mr_Nizzle
  • 6,644
  • 12
  • 55
  • 85
  • may be this will help you [Using Rails 3.1, where do you put your “page specific” javascript code?](http://stackoverflow.com/questions/6167805/using-rails-3-1-where-do-you-put-your-page-specific-javascript-code) – Arvind May 23 '13 at 06:54

2 Answers2

0

On production they are compiled into one file. I think the best answer for your question is to suggest atomize all these scripts so that they don't affect each other and keep all those files.

Michał Czapko
  • 1,948
  • 1
  • 16
  • 25
0

In any template file, even a partial, you can do, for example:

<% content_for :head do %>
  <%= javascript_include_tag "jquery.collapsibleFieldset" -%>
<% end %>

I'm on rails 3.0.9, so the default js scrunch is not enabled. However, I believe (assume) that js files included in an individual template (not in the layouts) would be excluded from the scrunch, in which case this should work fine.

And you can also create multiple layouts if that helps resolve some of your dependencies. E.g., if say part of your app is for admin related functionality like a cms, and the other part is for consumer related functionality.

pduey
  • 3,706
  • 2
  • 23
  • 31