> > so is the preferred approach than to rename all destroy methods, to > delete methods? >
noooooo!!!! oh boy, doing that would send you to merb/web hell right away! I gave you the solution in my previous email, you should NOT have a link (GET request) to a modifying action, you need to use buttons/form using a POST request.. You can certainly put your destroy code in your delete method but you and I won't be friend anymore ;) Just use the delete_button helper or follow the unobtrusive javascript method explained in my previous email. - Matt On Wed, Jan 7, 2009 at 9:52 PM, Justin Smestad <[email protected]>wrote: > > so is the preferred approach than to rename all destroy methods, to > delete methods? > > On Jan 7, 10:34 pm, "Matt Aimonetti" <[email protected]> wrote: > > Roy, if you look at the example I put in the wiki: > > > > resource(@article, :delete) # GET => delete > > > > A GET request to the delete action won't destroy the object, it should > > display a warning screen confirming that the user really wanted to > destroy > > the object. > > > > What justin is trying to do isn't possible in pure HTML. Let me explain > > quickly. > > > > A restful destroy action on a resource needs to be called using the > DELETE > > http verb/method. Browsers don't support all the http verbs such as > DELETE > > and UPDATE. Instead, merb cheats by doing a post and "stuff" the method > to > > us in a parameter. > > > > The same way you cannot POST with a link, you can't DELETE with a link > and > > that's why we have the delete_button helper which creates a form for you > and > > send call the destroy action by using the DELETE http verb in a request > made > > to the resource. > > > > So how does Rails do it? > > > > Rails uses a JS trick. You can also do the same thing using jQuery or > > Prototype. Here is an example extracted from > thehttp://merbclass.commaterial: > > > > view: > > > > <%= link_to "[delete]", resource(article, :delete), :class => > > "delete", :rel => resource(article) %> > > > > The code above would usually send the user to the delete action which has > a > > confirmation form which calls the destroy action. > > We can Ajaxify/enhance the process by adding the following snippet of JS: > > > > jQuery(function($) { > > $("a.delete").click(function() { > > // jQuery idiom that allows use of 'this' inside the callback > > var self = $(this); > > > > if(confirm("Are you sure you wish to delete this article")) { > > $.post($(this).attr("rel"), {"_method": "delete"}, function(json) { > > self.parents("li:first").remove(); > > $("div.notice").html(json.notice); > > }, "json"); > > } > > return false; > > }); > > > > }); > > > > As you can see, we are using the rel attibute to get the url of the > resource > > and we are "post"ing a request with a fake method ("_method") set to > > "delete". The controller returns a notice that we then display in the > view. > > > > If you want to learn more about this kind of advanced technics, you can > join > > us in the merb/rails3 training sessions:http://merbcamp.com;) > > > > I hope this helps. > > > > - Matt > > > > On Wed, Jan 7, 2009 at 8:56 PM, Roy Wright <[email protected]> wrote: > > > > > On Jan 7, 2009, at 10: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... > > > > > Try: > > > > > link_to('delete', resource(obj, :delete) > > > > > Here's a good reference: > > > > > http://wiki.merbivore.com/development/resource_urls > > > > > HTH, > > > Roy > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
