:mhfs


Truly making Rails3 use JQuery

Being myself a JQuery fan, I always make the change from Prototype to JQuery in the rails projects I start.

The addition of the --skip-prototype option to the rails command was certainly a huge progress, but (you’ll probably call me a purist) not being able to use javascript_include_tag :defaults with JQuery used to annoy me.

Not anymore. Reading Rails Inside I figured out there’s a way of teaching Rails what your defaults are.

Just create an initializer with the following content:

module ActionView::Helpers::AssetTagHelper
  remove_const :JAVASCRIPT_DEFAULT_SOURCES
  JAVASCRIPT_DEFAULT_SOURCES = %w(jquery.js rails.js)

  reset_javascript_include_default
end

And now your call to javascript_include_tag :defaults will include JQuery instead of Prototype.

Cheers!