如何使用Rails 3更新到jQuery 1.7+? [英] How can I update to the jQuery 1.7+ using Rails 3?

查看:57
本文介绍了如何使用Rails 3更新到jQuery 1.7+?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到此错误,我需要将我的Rails 3.1项目(我不使用资产管道)升级到jQuery 1.7 +.

I just noticed this error and I need to upgrade my Rails 3.1 project (I'm not using asset pipeline) to jQuery 1.7+.

我看到我的javascripts文件夹(public/javascripts)中已经有jQuery库.除了无需手动将新的jQuery库复制到其中,还有注释使用Ruby替换JavaScript文件吗?

I see that there are already jQuery libraries in my javascripts folder (public/javascripts). Short of copying the new jQuery library into there manually, is there a comment to replace the JavaScript file using Ruby?

推荐答案

在Rails 3.1中,jQuery由 jquery-rails gem管理.您可以使用jquery-rails的较新版本来升级jQuery版本.这很容易做到.这是完整的解释.

In Rails 3.1, jQuery is managed by the jquery-rails gem. You can upgrade your jQuery version by using a newer version of jquery-rails. It's very easy to do. Here's a full explanation.

通过从项目根目录运行gem list来查看现有版本.您可能会看到类似以下的内容:

See your existing version by running gem list from project root directory. You'll probably see something like this:

...
i18n (0.6.0)
jquery-rails (1.0.16, 1.0.14, 1.0.13)
json (1.6.1)
...

jquery-rails gem在版本1.0.17+中使用jQuery 1.7+.在撰写本文时,Rails 3.1的gem的最新版本是1.0.19,它使用jQuery 1.7.1.听起来像您想要的!

The jquery-rails gem uses jQuery 1.7+ in versions 1.0.17+. As of this writing, the latest version of the gem for Rails 3.1 is 1.0.19, which uses jQuery 1.7.1. That sounds like what you want!

因此,您无需在/javascripts文件夹中放入任何内容.相反,请在Gemfile中指定gem的较新版本.这是我的东西:

So you don't need to drop anything in your /javascripts folder. Instead, specify the newer version of the gem in your Gemfile. Here's what I have in mine:

gem "jquery-rails", "~>1.0.19"

有趣的~>字符告诉捆绑程序查找的gem版本至少是您指定的版本(此处为1.0.19),以及以后的任何次要版本,但不包括下一个主要版本(即2.0.0).此宝石,仅支持Rails 3.2 +).

The funny ~> character tells bundler to find a version of the gem that is at least what you specify (1.0.19 here), and any later minor releases, but not the next major release (which is 2.0.0 for this gem, supporting only Rails 3.2+).

然后,从项目根目录运行bundle,将为您设置指定的版本.重新启动Rails应用程序,重新加载页面,您应该能够验证自己正在使用jQuery 1.7.1.

Then, from the project root, run bundle and the specified version will be set up for you. Restart your Rails app, reload the page, and you should be able to verify that you are now dealing with jQuery 1.7.1.

让我知道怎么回事!

干杯.

这篇关于如何使用Rails 3更新到jQuery 1.7+?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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