Web Images Videos Maps News Shopping Google Mail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Adding a delete confirmation
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
KJoyner  
View profile   Translate to Translated (View Original)
 More options 25 Jan 2008, 01:19
From: KJoyner <K...@kjoyner.com>
Date: Thu, 24 Jan 2008 17:19:11 -0800 (PST)
Local: Fri 25 Jan 2008 01:19
Subject: Adding a delete confirmation
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google