Message from discussion
Adding a delete confirmation
MIME-Version: 1.0
Message-ID: <8ced4378-7ea2-43f2-9ac8-05b4ad3ea287@x69g2000hsx.googlegroups.com>
Date: Thu, 24 Jan 2008 17:19:11 -0800 (PST)
Received: by 10.100.141.5 with SMTP id o5mr725169and.11.1201223951664; Thu, 24
Jan 2008 17:19:11 -0800 (PST)
X-IP: 71.139.188.142
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET
CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe)
Subject: Adding a delete confirmation
From: KJoyner <K...@kjoyner.com>
To: Low Pro <low-pro@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
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,