I'm trying to execute a save action via AJAX using link_to
:
<%= link_to 'Save', image_path(image), method: :patch,
data:{ confirm: 'Save image?', remote: true } %>
I want the link to be replaced with <span>Saving...</span>
on confirmation, but can't figure out a clean way to do it.
Problems with existing solutions:
disable_with:
If I add :disable_with => '<span>Saving...</span>'
the inner HTML of the link will be replaced instead of the link itself. Don't want that.
onclick:
If I add :onclick => "$(this).replaceWith('<span>Saving...</span>');"
the link will be replaced immediately, even if the user cancels the confirmation
Is there a solution that fits with Rails 3 UJS best practices?