I would like to use jQuery instead of Prototype in my Rails 3 application.
What is the \"official\" Rails 3 way to do this?
It's extremely easy.
First, get rails.js from from the bottom of this page. That page also has a good set of instructions.
Then, put rails.js and jQuery itself in the public/javascripts directory. You can clear out all other files from that directory.
Finally, in application.rb, add the following:
config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
This assumes that your jQuery file is named jquery.js. That line tells Rails to automatically load jquery.js and rails.js whenever <%= javascript_include_tag :defaults %> is encountered.
That's it! Rails 3 automatically generates attributes on the elements jQuery needs to add events to, and jQuery reads those attributes and adds the necessary events.