Unobtrusive jQuery with Rails 3
-
1.4.3
-
1.4.4
-
1.4
-
1.4.1
-
1.4.2
rails.js file from v1.4 branch can be accessed at github.com/rails/jquery-ujs/blob/v1.4/src/rails.js .
Add this line to your Gemfile:
gem 'jquery-rails'
Run this command:
$ rails generate jquery:install # --ui if you want jQuery UI
Download jQuery from docs.jquery.com/Downloading_jQuery and put the file in public/javascripts. For example, the file might look like:
public/javascripts/jquery-1.4.4.min.js
Copy rails.js from github.com/rails/jquery-ujs/raw/master/src/rails.js into public/javascripts - overwriting the prototype one (you can also delete the other prototype files if you don’t need them for anything else.)
Switch the javascript_include_tag :defaults
to use jquery instead of the default prototype helpers. Uncomment following line from file config/application.rb
config.action_view.javascript_expansions[:defaults] = %w(jquery rails application)
$ gem install bundler $ bundle install
$ bundle exec ruby test/server.rb
Visit localhost:4567 and all the tests should pass.
At the top of the page you will see links to jQuery 1.4.3 and 1.4.4 . By clicking on those links you will be executing the tests against the clicked version of jquery. By default test uses jQuery 1.4.4 .