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
config.action_view.javascript_expansions[:defaults].unshift('my_prepend_1',
my_prepend_2')
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 = (remove_const
:JAVASCRIPT_DEFAULT_SOURCES).unshift('my_prepend_1', 'my_prepend_2')
reset_javascript_include_default
end
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