如何在Rails 3应用程序中使用jQuery而不是Prototype? [英] How to use jQuery instead of Prototype in a Rails 3 application?

查看:103
本文介绍了如何在Rails 3应用程序中使用jQuery而不是Prototype?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to use jQuery instead of Prototype in my Rails 3 application.

Rails 3的官方"方法是什么?

What is the "official" Rails 3 way to do this?

推荐答案

首先,您需要安装gem,方法是将以下行添加到Gemfile中:

First you need to install the gem, by adding this line to the Gemfile:

gem 'jquery-rails', '>= 0.2.6'

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

(and run bundle install) Then you need to go to the public/javascript folder and you need to replace the rails.js file by the one from: http://github.com/rails/jquery-ujs.

执行此操作的正确方法是:

The proper way of doing this is to do:

rails generate jquery:install

或者如果您要包括jQuery UI:

or if you want to include jQuery UI:

rails generate jquery:install --ui

在Github页面上:

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

This will remove the Prototype.js library from Rails, add latest jQuery library and fetch the adapter. Be sure to choose to overwrite the "rails.js" file.

这篇关于如何在Rails 3应用程序中使用jQuery而不是Prototype?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆