July 28th, 2010

Rails 3: Reset your Javascript include defaults

UPDATE: 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.

December 9th, 2009

Extend has_many with the :extend option

November 14th, 2009

Simple Two Way Encryption for Ruby on Rails

June 7th, 2009

Make .bashrc Work for You with Aliases

June 5th, 2009

A Developers Responsibility

February 5th, 2009

Annoy Your Friends With Emoji for Free & Without Jailbreaking Your iPhone

February 4th, 2009

Thoughts About My Dad and the Last 25 Years

January 14th, 2009

Growing Up Star Wars Is Stellar

January 11th, 2009

A New Year, A New Website

August 10th, 2008

Man dances in 42 countries