如何在Rails 3应用程序中使用jQuery而不是Prototype?

And*_*rew 10 jquery ruby-on-rails-3

我想在我的Rails 3应用程序中使用jQuery而不是Prototype.

什么是"官方"Rails 3方式这样做?

Amo*_*tir 25

首先,您需要通过将此行添加到Gemfile来安装gem:

gem 'jquery-rails', '>= 0.2.6'
Run Code Online (Sandbox Code Playgroud)

(然后运行bundle install)然后你需要转到public/javascript文件夹,你需要用以下内容替换rails.js文件:http://github.com/rails/jquery-ujs.

这样做的正确方法是:

rails generate jquery:install
Run Code Online (Sandbox Code Playgroud)

或者如果你想包含jQuery UI:

rails generate jquery:install --ui
Run Code Online (Sandbox Code Playgroud)

从Github页面:

这将从Rails中删除Prototype.js库,添加最新的jQuery库并获取适配器.请务必选择覆盖"rails.js"文件.