Dirk Bergmann

Developer, panographer. Does consultancy work from own company. Lives in Chiang Mai, Thailand.


Chiang Mai

Hua Hin

Thailand Hotels

ListVote - List. Vote. Learn.

Partnerseek - Find Partners

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:

 module ActionView::Helpers::AssetTagHelper
 :JAVASCRIPT_DEFAULT_SOURCES).unshift('my_prepend_1', 'my_prepend_2')

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.