Note that there are some explanatory texts on larger screens.

plurals
  1. POLocation of jquery.js and jquery-ujs.js and why destroy links do not work
    primarykey
    data
    text
    <p>I'm a bit confused. In a lot of questions on stackoverflow I read you need <a href="https://github.com/rails/jquery-ujs" rel="nofollow">jquery-ujs</a> to manage your javascript code, especially if you want these destroy links do work. If I go on this page to follow all the installation instructions I must say I have nothing to do.</p> <p>Because I'm using <strong>Rails 3.1</strong> I have to follow this:</p> <p><em>For automated installation in Rails, use the "jquery-rails" gem. Place this in your Gemfile:</em><br> <code>gem 'jquery-rails', '&gt;= 1.0.12'</code><br> <em>And run:</em> <code>$ bundle install</code><br> <em>This next step depends on your version of Rails.</em></p> <p><em>a. For <strong>Rails 3.1</strong>, add these lines to the top of your app/assets/javascripts/application.js file:</em></p> <pre><code>//= require jquery //= require jquery_ujs </code></pre> <p>But for <strong>Rails 3.1</strong> this is already done after creating a new rails app. </p> <p>If I run <code>$ rails generate jquery:install</code> I get the following output:</p> <pre><code>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. </code></pre> <p>Okay, nothing new. But why my destroy links still doesn't work. So I ask myself the question where are these jquery files located? When I read the jquery installation instruction for another rails version, there they always tell me to copy these files (jquery.js, jquery-ujs.js) to a specific location. Only as a Ruby 3.1 user you don't have to do this. But why? I can't find these files. Are they a part of the jquery-rails gem? If yes, why my destroy links still doesn't work? Is this really an issue of jquery? I mean if I change the helper from <code>link_to</code> to <code>button_to</code> it's working. So how it can be happen as long as it should be an issue of jquery? It might not matter to me, but I don't want to use a form button. Furthermore I can't believe that an application like Rails contains such a big issue in its common generated templates.</p> <p>So how to fix this without changing the <code>link_to</code> helper and without going away from javascript (<a href="http://railscasts.com/episodes/77-destroy-without-javascript" rel="nofollow">Railscast</a>)?</p> <p><strong>Update 1</strong> </p> <ul> <li>layout file has <code>&lt;%= javascript_include_tag "application" %&gt;</code> </li> <li><code>config.assets.enabled = true</code> is set</li> </ul> <p><strong>Update 2</strong> </p> <p>Here the source for the mentioned destroy links: </p> <pre><code>&lt;%= link_to 'Destroy', @post, confirm: 'Are you sure?', method: :delete %&gt; </code></pre> <p>Usually it should delete a post, but instead the browser is pointed to the location of that post, e.g. <code>http://domain/posts/2</code>.<br> If you run this with <code>button_to</code> instead of <code>link_to</code> it will work, but then its a form button.</p> <p><strong>Update 3</strong></p> <p>Okay, the destroy links work in Firefox, but I'm a Google Chrome user and I want it to work there as well. Is there a solution for this?</p> <p><strong>Update 4</strong></p> <p>Chrome Inspector throw a DOMException on line 5122: <code>var ret = matches.call( node, expr );</code></p> <p><code>message: "SYNTAX_ERR: DOM Exception 12"</code></p> <p>But this error occurs on every hyperlink whether it's a destroy link or not.<br> The destroy link throws an <strong>TypeError</strong>.<strike>, but I can't figure out if it comes from jquery.js or from a built in chrome extension.</strike> jquery-ujs.js throws the error and the message was "<em>Are you sure?</em>". That's the text defined by rails for a confirm message. So I removed the confirm option and after that the deletion worked.</p> <p>How to make the confirmation option work in Chrome?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload