Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Changing default Rails 3 confirmation alert behaviour with a click-twice approach
// This goes in application.js
// Using this, the confirmation alerts on Rails 3.1 will be replaced with this behaviour:
// The link text changes to 'Sure?' for 2 seconds. If you click the button again within 2 seconds the action is performed,
// otherwise the text of the link (or button) flips back and nothing happens.
$.rails.confirm = function(message, element)
var state ='state');
var txt = element.text();
if (!state)
{'state', 'last');
{'state', null);
}, 2000);
return false;
return true;
$.rails.allowAction = function(element)
var message ='confirm'),
answer = false, callback;
if (!message) { return true; }
if ($, 'confirm'))
// le extension.
answer = $.rails.confirm(message, element);
callback = $, 'confirm:complete', [answer]);
return answer && callback;
$.rails.handleLink = function(link)
if ('remote') !== undefined)
else if ('method'))
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.