zachinglis (owner)

Forks

Revisions

gist: 6624 Download_button fork
public
Description:
Unobtrusively have put and post links
Public Clone URL: git://gist.github.com/6624.git
Embed All Files: show embed
unobtrusive_put_post_links.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 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;
  });
});