Prepend to javascript_include_tag :defaults

Yes, there is register_javascript_include_default but it will only** append** to your sources.

To prepend (I’ll use this to have the excellent JS.Class libraries loaded before anything else), proceed like so:

While in Rails 3, you can set

in your application.rb file,

in Rails 2.3.x you create an initializer (e.g. config/initializers/my_js_defaults.rb) and reset the JAVASCRIPT_DEFAULT_SOURCES constant as so:

This post gave me the idea. It concerns Rails 3 (before the above config.action_view.javascript_expansions which was introduced in Rails 3 RC) but the code also works with Rails 2.3.x.

Posted: 10 December 2010

comments powered by Disqus