Skip to content

Instantly share code, notes, and snippets.

@mynameispj
Last active December 16, 2015 12:38
Show Gist options
  • Save mynameispj/5435402 to your computer and use it in GitHub Desktop.
Save mynameispj/5435402 to your computer and use it in GitHub Desktop.
Prettier Rails confirm dialogs
<%= link_to 'Delete this junk', junk_path(j), :method => :delete, :confirm => 'You sure you want to delete this junk?' %>
$.rails.confirmed = (link) ->
linkclass = link.attr 'class'
link.removeAttr('data-confirm')
link.trigger('click.rails')
if linkclass == 'reset-link'
window.location.replace(""+link.context.href+"");
$.rails.confirmed = (link) ->
link.removeAttr('data-confirm')
link.trigger('click.rails')
<%= link_to 'Reset this junk', reset_junk_path(j), :class => 'reset-link', :confirm => 'You sure you want to reset this junk?' %>
<%= link_to 'Reset this junk', reset_junk_path(j), :confirm => 'You sure you want to reset this junk?' %>
@edipofederle
Copy link

if linkclass.indexOf("reset-link") != -1 instead of if linkclass == 'reset-link' if your link_to have more that one class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment