| |
Low Pro |
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;
}
Thanks,
-- Ken