Topic: Delete link not working; JavaScript problem?

The code in my view is this:

<%= link_to 'Delete', record, :confirm => 'Are you sure?', :method => :delete %>

Which generates the expected HTML code:

<a href="/training_log/employee_jobs/41" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Delete</a>

However, clicking on the link fails to ask for confirmation, and sends the user to the show action, not the delete action:

Started GET "/training_log/employee_jobs/41" for at 2013-03-08 09:54:20 +0000

So I am thinking that this is an issue with Unobtrustive JavaScript; the data-confirm and data-method are not doing anything. I have a JavaScript function in a library that moves the cursor to the first input box on the page, and that works okay, so JavaScript is working. I have looked at the application.js file, and my focus-moving script is there, and there is some code that mentions both data-confirm and data-method, though whether it is the right code I could not say. Here is the snippet:

... var r;e.rails=r={linkClickSelector:"a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]",inputChangeSelector:"select[data-remote], input[data-remote], textarea[data-remote]",formSubmitSele ...

This is the manifest from application.js (f2 being my custom library):

//= require jquery
//= require f2
//= require prototype
//= require effects
//= require controls
//= require jquery_ujs
//= require jquery-ui

I have also tried it with the custom library absent to see if that was screwing it up - it was not. This is an old project that was originally written in an early Rails 2, and has been upgraded to more recent versions as and when, so it may be a legacy of that.

I am wondering if anyone can shed some light here?

By the way, I am precompiling assets in development here to mimic what happens in production. Rails 3.2.11 on JRuby 1.7.2.

Last edited by F2Andy (2013-03-08 07:10:26)

Re: Delete link not working; JavaScript problem?

Can you please post your routes.rb?