| |
Low Pro |
Remote.DeleteLink = Behavior.create(Remote.Base, {
onclick : function() {
var options = Object.extend({ url : this.element.href, method : '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