How many times do you heard you should separate content from behavior? Never? Hmmm don’t try to cheat me.. So, why do you still use :confirm
option for link_to
helper?
Here a little snippet to archive our goal, and as extra bonus, you get it i18n:
<script type="text/javascript">
window._authenticity_token = "";
</script>
t(:’asset.destroy’),
:class => “delete”,
:’data-confirm’ => t(:’asset.destroy_confirm’) %>
$(document).ready(function(){
$(".delete").bind("click", function() {
if(window.confirm($(this).attr("data-confirm"))) {
$.ajax({
url: $(element).attr("href"),
data: {
_method: "delete",
authenticity_token: window._authenticity_token
},
type: 'post',
dataType: 'script'
});
}
return false;
});
});