Created
July 29, 2008 15:14
-
-
Save dstrelau/3103 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ConfirmedDeleteButton = Class.create({ | |
initialize:function(anchor) { | |
this.anchor = anchor; | |
if (this.anchor.readAttribute('alt').blank()) { | |
this.confirmationText = 'Are you sure?'; | |
} else { | |
this.confirmationText = this.anchor.readAttribute('alt'); | |
} | |
this.anchor.observe('click', this.deleteFormSubmit.bindAsEventListener(this)); | |
}, | |
deleteFormSubmit: function(ev) { | |
ev.stop(); | |
if (confirm(this.confirmationText)) { | |
var f = document.createElement('form'); | |
f.style.display = 'none'; | |
this.anchor.parentNode.appendChild(f); | |
f.method = 'POST'; | |
f.action = this.anchor.href.gsub(/\/delete$/, ''); | |
var m = document.createElement('input'); | |
m.setAttribute('type', 'hidden'); | |
m.setAttribute('name', '_method'); | |
m.setAttribute('value', 'delete'); | |
f.appendChild(m); | |
var t = document.createElement('input'); | |
t.setAttribute('type', 'hidden'); | |
t.setAttribute('name', 'authenticity_token'); | |
t.setAttribute('value', authenticityToken); | |
f.appendChild(t); | |
f.submit(); | |
} | |
} | |
}); | |
document.observe('dom:loaded',function(){ | |
$$('a.confirmed-delete').each(function(a) { | |
new ConfirmedDeleteButton(a); | |
}); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map.resources :post, :member => {:delete => :get} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= link_to 'Delete', delete_post_path(@post), | |
:class => "confirmed-delete", | |
:alt => 'Are you sure you want to permanently delete this post?' %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment