kneath (owner)

Fork Of

gist: 6624 by zachinglis Unobtrusively have put and ...

Forks

Revisions

gist: 6643 Download_button fork
public
Public Clone URL: git://gist.github.com/6643.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
17
18
19
// 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($) {
  jQuery('.form_to_link').each(function(el){
    var form = el.parents('form');
    form.after('<a href="' + form.attr('action') + '" class="button_link_to">' + form_to_link.attr('value') + '</a>');
    form.hide();
    
    el.getElementsBySelector('.button_link_to').click(function(){
      form.submit();
      return false;
    });
  })
  
  
});