Rails 3: Reset your Javascript include defaults
Wednesday, July 28th, 2010UPDATE: This is not the best way to go about changing your JS library defaults. I noticed shortly after posting this that in the application.rb file there is a config to handle this. As of this update (8/11/10) this config option is not included at http://edgeguides.rubyonrails.org/configuring.html#configuring-action-view.
Back in the olden days of May 2010 if you wanted to change your default Javascript files in Rails you did something like what Rizwan Reza describes here (http://www.railsinside.com/tips/451-howto-unobtrusive-javascript-with-rails-3.html). However, in upgrading a side project to the latest Rails 3 release candidate (from Rails3b4, fwiw) there is a better way.
The post linked above uses the following code:
However, as of the date of this posting (7/28/2010) it appears this approach has been deprecated in favor of register_javascript_expansion (http://apidock.com).
I likey.
The above example should now be:
Boom.
Notice in the latter approach the inclusion of “application.js” in the expansion array. Don’t forget that one.
Simply add javascript_include_tag :your_new_default to my layout, and you’re ready to go.
I'm Eric Hurst, and I make the Internet from a comfy chair in Kansas City. Send an email to "eric at erichurst dot com" (spam is bad) to hire me.
