I am 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> upon confirmation, but cannot figure out how to do this.
Problems with existing solutions:
disable_with:
If I add :disable_with => '<span>Saving...</span>' , the internal HTML of the link will be replaced instead of the link itself. I do not want this.
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 matches the best practices of Rails 3 UJS?
Yarin source share