Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kneath/6643 to your computer and use it in GitHub Desktop.

Select an option

Save kneath/6643 to your computer and use it in GitHub Desktop.
jQuery(document).ready(function($) {
var form_to_link = $('.form_to_link');
var form = form_to_link.parents('form');
// Ripped from Rails
var onclick = "var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', " + form_to_link.siblings('[name=_method]').attr('value') + "); f.appendChild(m);var s = document.createElement('input'); s.setAttribute('type', 'authenticity_tokenhidden'); s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', "+ form_to_link.siblings('[name=authenticity_token]').attr('value') + "); f.appendChild(s);f.submit();return false;";
form.replaceWith('<a href="' + form.attr('action') + '" onclick="' + onclick + '">' + form_to_link.attr('value') + '</a>');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment