On Jan 7, 2009, at 8:39 PM, [email protected] wrote:

>
> I seem to have run into an odd issue. I am trying to create a simple
> link_to "delete", resource(@snippet), :method => 'delete' and it does
> not seem to work. It renders:
>
> <a method="delete" href="/snippets/5">delete</a>
>
> I am wondering how I can make this happen without using the
> delete_button helper...


        Here is how you can make it happen. You need this javascript in your  
app:

$(document).ready(function(){
   $('a[method]').livequery(function(){
     var message = $(this).attr('confirm');
     var method  = $(this).attr('method');

     if (!method && !message) return;

     $(this).click(function(event){
       if (message && !confirm(message)) {
         event.preventDefault();
         return;
       }

       if (method == 'post' || method == 'put' || method == 'delete') {
         event.preventDefault();

         var form = $("<form/>").attr('method', 'post').attr('action',  
this.href).attr('style', 'display: none');

         if (method != "post") {
           form.append($('<input type="hidden" name="_method"/ 
 >').attr('value', method));
         }
         form.insertAfter(this).submit();
       }
     });
   });
)};


Then you can use a normal link_to like this:

               = link_to "Destroy!", url(:decom, instance.id), :method  
=> :delete, :confirm => "Are you sure? There is no undo."


Cheers-
-Ezra


Ezra Zygmuntowicz
[email protected]




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to