Location of jquery.js and jquery-ujs.js and why link killing doesn't work

I am a bit confused. On many stackoverflow questions, I read that you need jquery-ujs to manage your javascript code, especially if you want these destruction links to work. If I go to this page to follow all the installation instructions, I have to say that I have nothing to do.

Since I'm using Rails 3.1 , I have to follow this:

For automatic installation in Rails, use the jquery-rails gem. Put this in your gemfile:
gem 'jquery-rails', '>= 1.0.12'
And run: $ bundle install
The next step depends on your version of Rails.

a. For Rails 3.1, add these lines to the top of the app / assets / javascripts / application.js file:

 //= require jquery //= require jquery_ujs 

But for Rails 3.1, this is already done after creating the new rails application.

If I run $ rails generate jquery:install , I get the following output:

 deprecated You are using Rails 3.1 with the asset pipeline enabled, so this generator is not needed. The necessary files are already in your asset pipeline. Just add `//= require jquery` and `//= require jquery_ujs` to your app/assets/javascripts/application.js If you upgraded your app from Rails 3.0 and still have jquery.js, rails.js, or jquery_ujs.js in your javascripts, be sure to remove them. If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator. 

Ok, nothing new. But why are my destruction links still not working. So I ask myself the question, where are these jquery files located? When I read the jquery installation instructions for another version of rails, they always tell me to copy these files (jquery.js, jquery-ujs.js) to a specific location. Just as a Ruby 3.1 user, you don’t have to do this. But why? I can not find these files. Are they part of the jquery-rails gem? If so, why are my destruction links still not working? Is this really a jquery problem? I mean, if I changed the helper from link_to to button_to , it worked. So how can this happen as long as this should be a jquery problem? It doesn’t matter to me, but I don’t want to use the form button. Also, I can't believe that an application like Rails contains such a big problem in its generic generated templates.

So, how to fix this without changing the link_to and without departing from javascript ( Railscast )?

Update 1

  • Layout file <%= javascript_include_tag "application" %>
  • config.assets.enabled = true set

Update 2

Here is the source for the destroy links mentioned:

 <%= link_to 'Destroy', @post, confirm: 'Are you sure?', method: :delete %> 

Usually it should delete the message, but instead the browser indicates the location of this message, for example. http://domain/posts/2 .
If you run this using button_to instead of link_to , it will work, but then its form button.

Update 3

Ok, destroy links work in Firefox, but I'm a Google Chrome user, and I want it to work there. Is there a solution for this?

Update 4

The Chrome Inspector will throw a DOMException on line 5122: var ret = matches.call( node, expr );

message: "SYNTAX_ERR: DOM Exception 12"

But this error occurs on every hyperlink, whether it is a link for destruction or not.
The destroy link contains a TypeError command. but I can't figure out if it comes from jquery.js or from the built-in chrome extension. jquery-ujs.js throws the error and the message was "Are you sure?". This is the text defined by the rails to confirm the message. So I removed the confirmation option and then deleted the job.

How do I configure the confirmation option in Chrome?

+4
source share
4 answers

Well, I can confirm that the “Best Pop Up Blocker” causes this behavior. Therefore, I suspect that something else with similar functionality will also cause the same problem.

On the plus side, with the above plugin, you can simply “whitelist” http://localhost , and everything starts working as intended!

+2
source

jquery.js and jquery_ujs.js are dynamically served by the asset pipeline and the jquery-rails gem. They no longer exist on disk in your Rails 3.1 application.

You can check if they are properly served by requesting /assets/jquery.js and /assets/jquery_ujs.js in your browser. Make sure they return JavaScript and not 404/500 error.

+4
source

Sounds like a javascript error ... you can:

  • publish the page on the hero where we can see
  • remove all your javascript code until it works, add it back until it works.

Also, make sure you don't include jquery.js and jquery-ujs.js twice (as if it seems like you are doing this). You mentioned that you have script tags with jquery.js and jquery-ujs.js ... don't do this.

Instead, your /assets/javascripts/application.js application should look like this:

 // //= require jquery //= require jquery_ujs //= require_tree . 

This will add jquery, jquery_ujs and all javascripts to your app / assets / javascripts folder.

+1
source

A few weeks ago, I just turned off all Chrome extensions, restarted Chrome, and everything worked fine. I don’t know which Chrome extensions I used at the time I created this question. The only thing I know is one extension that extends and distorts javascript code. This is the reason for all these strange error messages viewed by the Chrome Inspector. I don’t know what kind of extension it was, but it should be one of the most popular ad blockers or pop-ups. Just disable all Chrome extensions and find out if your code is working now.

0
source

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


All Articles