Message from discussion
Adding a delete confirmation
Received: by 10.35.13.4 with SMTP id q4mr29632pyi.7.1201224894945;
Thu, 24 Jan 2008 17:34:54 -0800 (PST)
Return-Path: <m...@aimonetti.net>
Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.226])
by mx.google.com with ESMTP id a28si1781704pye.0.2008.01.24.17.34.54;
Thu, 24 Jan 2008 17:34:54 -0800 (PST)
Received-SPF: neutral (google.com: 64.233.162.226 is neither permitted nor denied by best guess record for domain of m...@aimonetti.net) client-ip=64.233.162.226;
Authentication-Results: mx.google.com; spf=neutral (google.com: 64.233.162.226 is neither permitted nor denied by best guess record for domain of m...@aimonetti.net) smtp.mail=m...@aimonetti.net
Received: by nz-out-0506.google.com with SMTP id i28so346843nzi.5
for <low-pro@googlegroups.com>; Thu, 24 Jan 2008 17:34:54 -0800 (PST)
Received: by 10.142.201.3 with SMTP id y3mr923530wff.1.1201224894601;
Thu, 24 Jan 2008 17:34:54 -0800 (PST)
Received: by 10.143.19.13 with HTTP; Thu, 24 Jan 2008 17:34:54 -0800 (PST)
Message-ID: <f58d8dcb0801241734l66d81ad2t5db054dc198bb089@mail.gmail.com>
Date: Thu, 24 Jan 2008 17:34:54 -0800
From: "Matt Aimonetti" <mattaimone...@gmail.com>
Sender: m...@aimonetti.net
To: low-pro@googlegroups.com
Subject: Re: Adding a delete confirmation
In-Reply-To: <8ced4378-7ea2-43f2-9ac8-05b4ad3ea287@x69g2000hsx.googlegroups.com>
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_23041_21073203.1201224894604"
References: <8ced4378-7ea2-43f2-9ac8-05b4ad3ea287@x69g2000hsx.googlegroups.com>
------=_Part_23041_21073203.1201224894604
Content-Type: text/plain; charset=ISO-8859-1
Remote.DeleteLink = Behavior.create(Remote.Base, {
onclick : function() {
var options = Object.extend({ url : this.element.href, method : 'delete'
}, this.options);
if (confirm('Are you sure?')){
return this._makeRequest(options);
}else{
return false;
}
}
});
don't change your route, a delete action should not be a GET but a DELETE.
I'm sure my code could be cleaned up by extending Remote.Link but oh well,
this was a quick hack.
-Matt
On 1/24/08, KJoyner <K...@kjoyner.com> wrote:
>
>
> I am trying to use Low Pro to add a delete confirmation. In my
> controller, I have added a delete and a destroy action. These content
> of these actions are:
>
> def delete
> @item = Item.find( params[ :id ] )
> end
>
> def destroy
>
> @item = Item.find( params[ :id ] )
> item.destroy
>
> redirect_to items_path
> end
>
> In the routes, I add a delete route to items by:
>
> map.resources :items, :member => { :delete => :get }
>
> I then have a view where I add a delete link like this (also using
> haml):
>
> = link_to "delete", delete_item_path( item ), :class => 'delete'
>
> All of this works when I have javascript disabled. Now I am trying to
> add a behavior that will do the confirmation in javascript and if
> confirmed then redirect to the destroy action. I am trying to do this
> as follows but it is not working.
>
> Remote.Delete = Behavior.create( Remote.Base, {
> onclick: function( event ) {
> if ( confirm( 'Are you sure?' ) ) {
> var destroy_url = this.element.href.gsub( '/delete$', '' );
> options = Object.extend( { url: destroy_url, method: 'delete' },
> this.options );
> return this._makeRequest( options )
> }
> return false;
> }
> });
>
> Event.addBehavior( {
> '.delete' : Remote.Delete
> });
>
> The onclick gets executed but it is not working correctly. Any help
> would be appriciated.
>
> Thanks,
>
> -- Ken
> >
>
------=_Part_23041_21073203.1201224894604
Content-Type: text/html; charset=ISO-8859-1
Remote.DeleteLink = Behavior.create(Remote.Base, {<br> onclick : function() {<br> var options = Object.extend({ url : this.element.href, method : 'delete' }, this.options);<br> if (confirm('Are you sure?')){
<br> return this._makeRequest(options);<br> }else{<br> return false;<br> }<br> }<br>});<br><br>don't change your route, a delete action should not be a GET but a DELETE.<br><br>I'm sure my code could be cleaned up by extending
Remote.Link but oh well, this was a quick hack.<br><br>-Matt<br><br><br><div><span class="gmail_quote">On 1/24/08, <b class="gmail_sendername">KJoyner</b> <<a href="mailto:K...@kjoyner.com">K...@kjoyner.com</a>> wrote:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>I am trying to use Low Pro to add a delete confirmation. In my<br>controller, I have added a delete and a destroy action. These content
<br>of these actions are:<br><br>def delete<br> @item = Item.find( params[ :id ] )<br>end<br><br>def destroy<br><br> @item = Item.find( params[ :id ] )<br> item.destroy<br><br> redirect_to items_path<br>end<br><br>In the routes, I add a delete route to items by:
<br><br>map.resources :items, :member => { :delete => :get }<br><br>I then have a view where I add a delete link like this (also using<br>haml):<br><br>= link_to "delete", delete_item_path( item ), :class => 'delete'
<br><br>All of this works when I have javascript disabled. Now I am trying to<br>add a behavior that will do the confirmation in javascript and if<br>confirmed then redirect to the destroy action. I am trying to do this<br>
as follows but it is not working.<br><br>Remote.Delete = Behavior.create( Remote.Base, {<br> onclick: function( event ) {<br> if ( confirm( 'Are you sure?' ) ) {<br> var destroy_url = this.element.href.gsub
( '/delete$', '' );<br> options = Object.extend( { url: destroy_url, method: 'delete' },<br>this.options );<br> return this._makeRequest( options )<br> }<br> return false;<br> }<br>
});<br><br>Event.addBehavior( {<br> '.delete' : Remote.Delete<br>});<br><br>The onclick gets executed but it is not working correctly. Any help<br>would be appriciated.<br><br>Thanks,<br><br>-- Ken<br>
------=_Part_23041_21073203.1201224894604--