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?