How do I change JAVASCRIPT_DEFAULT_SOURCES for my application?

Posted by Adam Lassek on Stack Overflow See other posts from Stack Overflow or by Adam Lassek
Published on 2010-01-19T00:45:57Z Indexed on 2010/03/13 22:25 UTC
Read the original article Hit count: 382

Filed under:
|

When you call javascript_include_tag :defaults you usually get: prototype.js, effects.js, dragdrop.js, and controls.js.

These are stored in a constant in ActionView::Helpers::AssetTagHelper called 'JAVASCRIPT_DEFAULT_SOURCES`. My application uses jQuery, so I want to replace the Prototype references with something more useful.

I added an initializer with these lines, based on the source code from jRails:

ActionView::Helpers::AssetTagHelper::JAVASCRIPT_DEFAULT_SOURCES = %w{ jquery-1.4.min jquery-ui jquery.cookie }
ActionView::Helpers::AssetTagHelper::reset_javascript_include_default

But when I do this, I get: warning: already initialized constant JAVASCRIPT_DEFAULT_SOURCES during startup.

What's the correct way of changing this value? In the source code it checks for the constant before setting it, but apparently that happens before it runs the initializer scripts.


The Rails 3.0 release will provide much greater flexibility with choice of JS libraries, so I guess this is a problem with an expiration date.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about JavaScript