Dealing with conflicting javascript libraries in a Rails 3 app
Id like to understand the best approach when using multiple (and conflicting) javascript libraries in a rails 3 app. Before the js conflict was raised, I used the application.html.erb template to define all javascript libraries template on all pages with:
<%= javascript_include_tag :all %>
I intended to cache all the js files into one file. However, when I added a page using the mootool js library, a few of my other pages broke and I couldn't resolve the issue by modifying the js libraries. I've found a solution by creating a new controller for the pages that utilize the mootool library - then I created a template for that controller that does not use the application template that the other (non-mootool) pages use.
When dealing with a conflicting library, do I need to create a new controller (with a new head section that defines the js libraries), or this there a better solution.
Also, can I no longer cache all lib开发者_Python百科raries into one file? Im thinking I can create a partial with all the javascript libraries that don't conflict (and cache them) and link to the partial in the application template. And on the pages that use mootools, I'll link to that partial and also declare the mootool js library.
I was able to find part of the answer by digging up an old-school RailsCast where Ryan Bates explains how to pick a layout for only one action in a controller. Basic stuff.
The better solution is to resolve the conflicting javascript libraries so that I won't have to use multiple layouts.
精彩评论