How can I upgrade jQuery 1.7+ using Rails 3?

I noticed this error , and I need to update the Rails 3.1 project (I do not use the resource pipeline) for jQuery 1.7+.

I see that there are already jQuery libraries in my javascripts (public / javascripts) folder. If you have not manually copied the new jQuery library, is there a comment for replacing a JavaScript file with Ruby?

+6
source share
3 answers

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

See the existing version by running gem list from the project root directory. You will 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 driver uses jQuery 1.7+ in versions 1.0.17+. At the time of this writing, the latest gem for Rails 3.1 is 1.0.19, which uses jQuery 1.7.1. It looks like what you want!

Therefore, you do not need to drop anything into your /javascripts folder. Instead, specify the new gem version in the Gemfile . Here's what I have in mine:

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

The attractive character ~> tells the linker to find a version of the gem that is at least what you specified (1.0.19 here), and any subsequent 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 configured for you. Reload the Rails application, reload the page, and you can make sure that you are now dealing with jQuery 1.7.1.

Let me know how this happens!

Greetings.

+13
source

In Rails 4, you can update jquery as follows

in application.js manifest

 //= require jquery2 //for jquery 2 //= require jquery3 //for jquery 3 
+1
source

I upgraded the jQuery-rails gem version to version 3.1.2 (type: bundle show jquery-rails to see the current version of jquery-rails or gem list to see all the gems)

However, my webpage still used the deprecated version of jQuery 1.3. To check which version you are using, go to the jquery.js file, which is located in the assets / javascripts folder, the version should be indicated there. Of course, to use jquery, you must also include jquery.js in your /javascripts/application.js file by adding the following line:

 //= require jquery 

And in the event that you also have other JS libraries, for example, a prototype, you will definitely want to check this link as well: jQuery - preventing conflicts with other libraries

In any case, in accordance with the zzg recommendation above, I opened the link that he provided: Last Jquery and literally copied and pasted the contents of this web page into the jquery.js file. After I restarted the server and updated my web page, my jquery used the latest version. My jQuery worked locally on my dev env, but didn't immediately work on production (trying to figure it out right now).

Finally, another thing that may be useful for you to know is that you can always see which version the rails application uses (in your local env) by right-clicking on the rails application web page and selecting "View Page Source ", you should find a link like this:

<script data-turbolinks-track="false" src="/assets/jquery.js?body=1"></script >

By clicking on it, you will show the contents of your jquery.js file, which indicates the version (this will not work during production, since the resource pipeline compresses all javascript files into a single file, namely application.js)

0
source

Source: https://habr.com/ru/post/904636/


All Articles