Skip to content

Instantly share code, notes, and snippets.

Created October 29, 2012 22:44
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Custom confirmation dialog in Rails
# Coffeescript
$.rails.allowAction = (link) ->
return true unless link.attr('data-confirm')
$.rails.showConfirmDialog(link) # look bellow for implementations
false # always stops the action since code runs asynchronously
$.rails.confirmed = (link) ->
### Boostrap
$.rails.showConfirmDialog = (link) ->
message = link.attr 'data-confirm'
html = """
<div class="modal" id="confirmationDialog">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Are you sure Mr. President?</h3>
<div class="modal-body">
<div class="modal-footer">
<a data-dismiss="modal" class="btn">Cancel</a>
<a data-dismiss="modal" class="btn btn-primary confirm">OK</a>
$('#confirmationDialog .confirm').on 'click', -> $.rails.confirmed(link)
### jQueryUI
$.rails.showConfirmDialog = (link) ->
message = link.attr 'data-confirm'
html = """
<div id="dialog-confirm" title="Are you sure Mr. President?">
resizable: false
modal: true
OK: ->
$.rails.confirmed link
$(this).dialog "close"
Cancel: ->
$(this).dialog "close"
### Noty (
$.rails.showConfirmDialog = (link) ->
message = link.attr 'data-confirm'
okButton =
type: 'btn btn-primary'
text: 'Ok'
click: (noty) -> $.rails.confirmed(link); noty.close()
cancelButton =
type: 'btn btn-danger'
text: 'Cancel'
click: (noty) -> noty.close()
text: message
buttons: [okButton, cancelButton]
closable: false
timeout: false
modal: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment