When installing jQuery, why is my delete link broken?

I have a Rails 3 application that can create and delete products. The index page lists all products. Next to each product in the list is a delete link:

<%= link_to "Delete", product, :method => :delete, :title => "Delete" %>

It looks like this in HTML:

<a href="/products/104" data-method="delete" rel="nofollow" title="Delete">Delete</a>

This is working fine.

I got to the point that I want to install jQuery in my application. I followed the steps available on several web pages (e.g. this or this , for example).

After installing jQuery, the above delete link breaks. Instead of handling the action destroyin ProductsControllerRails, it tries to process the action show!

I assume that this is because the web browser cannot send requests DELETEinitially, so Rails "fakes" such requests using JavaScript, so before trying to install jQuery I had the following line:

<%= javascript_include_tag :defaults %>

Edit: something during the installation of jQuery was supposed to make the javascript used to "fake" the request DELETEno longer work, resulting in an action being called show. But what exactly is happening, I do not know ...

Does anyone have any ideas? Thank.

+3
source share
2 answers

JavaScript. , jQuery jQuery Rails (. http://github.com/BinaryMuse/rails-book/blob/master/app/views/layouts/application.html.haml#L6-L7):

<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" %>
<%= javascript_include_tag "rails" %>

(, rails.js jQuery http://github.com/rails/jquery-ujs/blob/master/src/rails.js).

+6

, jquery, 1.4.4:

<%= javascript_include_tag   
"http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js","rails" %>
0

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


All Articles