Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update to the jQuery 1.7+ using Rails 3?

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+.

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?

like image 892
Homan Avatar asked Dec 28 '11 22:12

Homan


1 Answers

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.

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)
...

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!

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"

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+).

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.

Let me know how it goes!

Cheers.

like image 104
brookr Avatar answered Oct 05 '22 07:10

brookr