views:

30

answers:

2

I didn't skip prototype when I began my new project and I want to move to JQuery. What is the best way to switch libraries?

+1  A: 

You can delete the prototype/scriptaculous and rails.js libraries. Then copy jquery and the ujs adapter for jquery to you javascripts directory and include them in your layout.

I recommend checking out the rails3-generators plugin. It provides generators for common tasks like this. In the jquery case you would just run the rails g jquery:install generator and the files would be copied for you and the JAVASCRIPT_DEFAULT_SOURCES set in an initializer so that javascript_include_tag :defaults still works.

Sam C
this is also covered in Railscasts #205 at 10:55
CountCet
A: 

Update for Rails 3.0 RC:

I've also been using the JAVASCRIPT_DEFAULT_SOURCES reset technique in an initializer for the betas, but have discovered that this is has been removed in Rails 3 RC, which will break your app.

You will typically see either an "undefined method `reset_javascript_include_default'" error or "constant ActionView::Helpers::AssetTagHelper::JAVASCRIPT_DEFAULT_SOURCES not defined (NameError)"

The fix / what's changed

The rails maintainers have refactored the javascript asset tag helpers and moved the default scripts setup within the railtie. So you simply need to use the following in application.rb:

config.action_view.javascript_expansions = { :defaults => ['jquery', 'rails', 'etc'] }

Apologies for my long rambling intro, before the meat - I put it there to help people Googling this issue.

Scott Lowe