This project is archived and is in readonly mode.

#4156 ✓duplicate

link_to doesn't behave when using image_tag and :confirm or :remote

Reported by Robs | March 12th, 2010 @ 05:28 AM | in 3.0.2

For example, this works fine:

<%= link_to 'Destroy', item, :confirm => 'Are you sure?', :method => :delete, :remote => true %>

However, this ignores the :confirm and :remote (:method appears to be respected):

<%= link_to image_tag('delete.png'), item, :confirm => 'Are you sure?', :method => :delete, :remote => true %>

I believe this has to do with $(document.body).observe("click", function(event) {...}) in rails.js. In the first line of code above, event.findElement() returns the link element. However in the second line of code, event.findElement() returns the image element.

If "a" is passed to event.findElement() it seems to traverse the dom correctly and find the link element:

// ...
$(document.body).observe("click", function(event) {
  var message = event.findElement("a").readAttribute('data-confirm');
// ...

Does this work?

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

Referenced by