Skip to content

Instantly share code, notes, and snippets.

@zachinglis
Created August 21, 2008 19:49
Show Gist options
  • Save zachinglis/6624 to your computer and use it in GitHub Desktop.
Save zachinglis/6624 to your computer and use it in GitHub Desktop.
Unobtrusively have put and post links
// Examples:
//
// button_to "Mark as unread", mark_as_unread_message_path(message), :method => :put, :class => "form_to_link"
// button_to "New Alert", new_alert
//
jQuery(document).ready(function($) {
var form_to_link = jQuery('.form_to_link');
var form = form_to_link.parents('form');
form.after('<a href="' + form.attr('action') + '" class="button_link_to">' + form_to_link.attr('value') + '</a>');
form.hide();
jQuery('.button_link_to').click(function(){
form.submit();
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment